Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / ooxml / modelpreprocess.xsl
blobb85f5a719820db298ab06b106e34ed77efa82e54
1 <!--
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 -->
18 <xsl:stylesheet
19 version="1.0"
20 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21 xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
22 xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
23 xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
24 xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
25 xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
26 xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
27 xmlns:xlink="http://www.w3.org/1999/xlink"
28 xmlns:dc="http://purl.org/dc/elements/1.1/"
29 xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
30 xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
31 xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
32 xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
33 xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
34 xmlns:math="http://www.w3.org/1998/Math/MathML"
35 xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
36 xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
37 xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
38 xmlns:ooo="http://openoffice.org/2004/office"
39 xmlns:ooow="http://openoffice.org/2004/writer"
40 xmlns:oooc="http://openoffice.org/2004/calc"
41 xmlns:dom="http://www.w3.org/2001/xml-events"
42 xmlns:xforms="http://www.w3.org/2002/xforms"
43 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
44 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
45 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
46 xmlns:rng="http://relaxng.org/ns/structure/1.0"
47 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
48 xmlns:UML = 'org.omg.xmi.namespace.UML' xml:space="default">
49 <xsl:output method="xml" />
51 <xsl:key name="namespace-aliases" match="//namespace-alias" use="@name"/>
53 <xsl:template match="/">
54 <xsl:apply-templates/>
55 </xsl:template>
57 <xsl:template name="prefixfromurl">
58 <xsl:param name="url"/>
59 <xsl:variable name="prefix" select="key('namespace-aliases', $url)/@alias"/>
60 <xsl:choose>
61 <xsl:when test="string-length($prefix) > 0">
62 <xsl:value-of select="$prefix"/>
63 </xsl:when>
64 <xsl:otherwise>
65 <xsl:value-of select="translate(substring-after($url, 'http://'), '/.', '__')"/>
66 </xsl:otherwise>
67 </xsl:choose>
68 </xsl:template>
70 <xsl:template name="prefixforgrammar">
71 <xsl:variable name="ns" select="ancestor::namespace/rng:grammar/@ns"/>
72 <xsl:variable name="prefix" select="key('namespace-aliases', $ns)/@alias"/>
73 <xsl:choose>
74 <xsl:when test="string-length($prefix) > 0">
75 <xsl:value-of select="$prefix"/>
76 </xsl:when>
77 <xsl:otherwise>
78 <xsl:call-template name="prefixfromurl">
79 <xsl:with-param name="url" select="$ns"/>
80 </xsl:call-template>
81 </xsl:otherwise>
82 </xsl:choose>
83 </xsl:template>
85 <xsl:template name="nsforgrammar">
86 <xsl:value-of select="ancestor::namespace/rng:grammar/@ns"/>
87 </xsl:template>
89 <xsl:template match="rng:element[@name|./rng:anyName] | rng:attribute[@name] | element | attribute">
90 <xsl:variable name="prefix">
91 <xsl:choose>
92 <xsl:when test="contains(@name, ':')">
93 <xsl:variable name="myname" select="@name"/>
94 <xsl:call-template name="prefixfromurl">
95 <xsl:with-param name="url" select="string(namespace::*[local-name(.) = substring-before($myname, ':')])"/>
96 </xsl:call-template>
97 </xsl:when>
98 <xsl:when test="name(.)='attribute'">
99 <xsl:if test="ancestor::namespace/rng:grammar/@attributeFormDefault='qualified'">
100 <xsl:call-template name="prefixforgrammar"/>
101 </xsl:if>
102 </xsl:when>
103 <xsl:otherwise>
104 <xsl:call-template name="prefixforgrammar"/>
105 </xsl:otherwise>
106 </xsl:choose>
107 </xsl:variable>
108 <xsl:variable name="ns">
109 <xsl:choose>
110 <xsl:when test="contains(@name, ':')">
111 <xsl:variable name="myname" select="@name"/>
112 <xsl:value-of select="string(namespace::*[local-name(.) = substring-before($myname, ':')])"/>
113 </xsl:when>
114 <xsl:when test="name(.)='attribute'">
115 <xsl:if test="ancestor::rng:grammar/@attributeFormDefault='qualified'">
116 <xsl:call-template name="nsforgrammar"/>
117 </xsl:if>
118 </xsl:when>
119 <xsl:otherwise>
120 <xsl:call-template name="nsforgrammar"/>
121 </xsl:otherwise>
122 </xsl:choose>
123 </xsl:variable>
124 <xsl:variable name="localname">
125 <xsl:choose>
126 <xsl:when test="contains(@name, ':')">
127 <xsl:value-of select="substring-after(@name, ':')"/>
128 </xsl:when>
129 <xsl:when test="./rng:anyName">
130 <xsl:text>FAST_TOKENS_END</xsl:text>
131 </xsl:when>
132 <xsl:otherwise>
133 <xsl:value-of select="@name"/>
134 </xsl:otherwise>
135 </xsl:choose>
136 </xsl:variable>
137 <xsl:copy>
138 <xsl:apply-templates select="@*"/>
139 <xsl:attribute name="enumname">
140 <xsl:if test="string-length($prefix) > 0">
141 <xsl:value-of select="$prefix"/>
142 <xsl:text>:</xsl:text>
143 </xsl:if>
144 <xsl:value-of select="$localname"/>
145 </xsl:attribute>
146 <xsl:attribute name="qname">
147 <xsl:if test="string-length($ns) > 0">
148 <xsl:value-of select="$ns"/>
149 <xsl:text>:</xsl:text>
150 </xsl:if>
151 <xsl:value-of select="$localname"/>
152 </xsl:attribute>
153 <xsl:attribute name="prefix">
154 <xsl:value-of select="$prefix"/>
155 </xsl:attribute>
156 <xsl:attribute name="localname">
157 <xsl:value-of select="$localname"/>
158 </xsl:attribute>
159 <xsl:apply-templates/>
160 </xsl:copy>
161 </xsl:template>
163 <xsl:template match="rng:grammar">
164 <xsl:copy>
165 <xsl:apply-templates select="@*"/>
166 <xsl:attribute name="application">
167 <xsl:value-of select="substring-before(substring-after(@ns, 'http://schemas.openxmlformats.org/'), '/')"/>
168 </xsl:attribute>
169 <xsl:apply-templates/>
170 </xsl:copy>
171 </xsl:template>
173 <xsl:template match="node()|@*">
174 <xsl:copy>
175 <xsl:apply-templates select="@*"/>
176 <xsl:apply-templates/>
177 </xsl:copy>
178 </xsl:template>
180 <xsl:template match="model">
181 <xsl:copy>
182 <xsl:apply-templates select="@*"/>
183 <xsl:apply-templates/>
184 </xsl:copy>
185 </xsl:template>
187 <xsl:template match="rng:define|rng:ref">
188 <xsl:copy>
189 <xsl:apply-templates select="@*"/>
190 <xsl:attribute name="classfordefine">
191 <xsl:variable name="name" select="@name"/>
192 <xsl:choose>
193 <xsl:when test="(starts-with(@name, 'CT_') or starts-with(@name, 'EG_') or starts-with(@name, 'AG_'))">1</xsl:when>
194 <xsl:when test="ancestor::namespace//start[@name=$name]">1</xsl:when>
195 <xsl:otherwise>0</xsl:otherwise>
196 </xsl:choose>
197 </xsl:attribute>
198 <xsl:apply-templates/>
199 </xsl:copy>
200 </xsl:template>
202 <xsl:template match="namespace">
203 <xsl:variable name="ns" select=".//rng:grammar/@ns"/>
204 <xsl:copy>
205 <xsl:apply-templates select="@*"/>
206 <xsl:attribute name="namespacealias">
207 <xsl:value-of select="key('namespace-aliases', $ns)/@alias"/>
208 </xsl:attribute>
209 <xsl:attribute name="prefix"><xsl:value-of select="translate(substring-after($ns, 'http://schemas.openxmlformats.org/'), '/-', '__')"/></xsl:attribute>
210 <xsl:apply-templates/>
211 </xsl:copy>
212 </xsl:template>
213 </xsl:stylesheet>