Bump version to 4.1-6
[LibreOffice.git] / writerfilter / source / ooxml / modelcleanup.xsl
blobc65a3ef3967a5454f0637ee174c7016e8ce8f22a
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:rng="http://relaxng.org/ns/structure/1.0"
22 xmlns:xalan="http://xml.apache.org/xalan"
23 exclude-result-prefixes = "xalan"
24 xml:indent="true">
25 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
28 <xsl:key name="resources"
29 match="resource[not(@generated)]" use="@name" />
31 <xsl:key name="resourcetags"
32 match="resource/@tag" use="ancestor::resource/@name"/>
34 <xsl:template name="generateresource">
35 <xsl:param name="resource"/>
36 <xsl:element name="resource">
37 <xsl:attribute name="name">
38 <xsl:value-of select="@name"/>
39 </xsl:attribute>
40 <xsl:attribute name="resource">
41 <xsl:value-of select="$resource"/>
42 </xsl:attribute>
43 <xsl:attribute name="generated">
44 <xsl:text>yes</xsl:text>
45 </xsl:attribute>
46 <xsl:for-each select="key('resourcetags', @name)">
47 <xsl:attribute name="tag">
48 <xsl:value-of select="."/>
49 </xsl:attribute>
50 </xsl:for-each>
51 </xsl:element>
52 </xsl:template>
54 <xsl:key name="nsaliases" match="//namespace-alias" use="@name"/>
56 <xsl:template name="resourcevalues">
57 <xsl:variable name="definename" select="@name"/>
58 <xsl:variable name="namespace" select="key('nsaliases', ancestor::namespace/rng:grammar/@ns)/@alias"/>
59 <xsl:element name="resource">
60 <xsl:attribute name="name">
61 <xsl:value-of select="@name"/>
62 </xsl:attribute>
63 <xsl:attribute name="resource">List</xsl:attribute>
64 <xsl:attribute name="generated">yes</xsl:attribute>
65 <xsl:for-each select="key('resourcetags', @name)">
66 <xsl:attribute name="tag">
67 <xsl:value-of select="."/>
68 </xsl:attribute>
69 </xsl:for-each>
70 <xsl:for-each select=".//rng:value">
71 <xsl:element name="value">
72 <xsl:attribute name="name">
73 <xsl:value-of select="translate(., '-+ ,', 'mp__')"/>
74 </xsl:attribute>
75 <xsl:attribute name="tokenid">
76 <xsl:text>ooxml:Value_</xsl:text>
77 <xsl:value-of select="translate($namespace, '-', '_')"/>
78 <xsl:text>_</xsl:text>
79 <xsl:value-of select="$definename"/>
80 <xsl:text>_</xsl:text>
81 <xsl:value-of select="translate(., '-+ ,', 'mp__')"/>
82 </xsl:attribute>
83 <xsl:value-of select="."/>
84 </xsl:element>
85 </xsl:for-each>
86 </xsl:element>
87 </xsl:template>
89 <xsl:template name="typeofdefine">
90 <xsl:for-each select="rng:data">
91 <xsl:choose>
92 <xsl:when test="@type='base64Binary'">
93 <xsl:text>String</xsl:text>
94 </xsl:when>
95 <xsl:when test="@type='boolean'">
96 <xsl:text>Boolean</xsl:text>
97 </xsl:when>
98 <xsl:when test="@type='byte'">
99 <xsl:text>Integer</xsl:text>
100 </xsl:when>
101 <xsl:when test="@type='dateTime'">
102 <xsl:text>String</xsl:text>
103 </xsl:when>
104 <xsl:when test="@type='decimal'">
105 <xsl:text>Integer</xsl:text>
106 </xsl:when>
107 <xsl:when test="@type='float'">
108 <xsl:text>Float</xsl:text>
109 </xsl:when>
110 <xsl:when test="@type='hexBinary'">
111 <xsl:text>Hex</xsl:text>
112 </xsl:when>
113 <xsl:when test="@type='int'">
114 <xsl:text>Integer</xsl:text>
115 </xsl:when>
116 <xsl:when test="@type='integer'">
117 <xsl:text>Integer</xsl:text>
118 </xsl:when>
119 <xsl:when test="@type='positiveInteger'">
120 <xsl:text>Integer</xsl:text>
121 </xsl:when>
122 <xsl:when test="@type='string'">
123 <xsl:text>String</xsl:text>
124 </xsl:when>
125 <xsl:when test="@type='token'">
126 <xsl:text>Integer</xsl:text>
127 </xsl:when>
128 <xsl:when test="@type='unsignedInt'">
129 <xsl:text>Integer</xsl:text>
130 </xsl:when>
131 <xsl:when test="@type='unsignedLong'">
132 <xsl:text>Integer</xsl:text>
133 </xsl:when>
134 <xsl:otherwise>
135 <xsl:text>Unknown</xsl:text>
136 </xsl:otherwise>
137 </xsl:choose>
138 </xsl:for-each>
139 </xsl:template>
141 <xsl:template name="typeofattribute">
142 <xsl:for-each select="rng:ref">
143 <xsl:variable name="name" select="@name"/>
144 <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
145 <xsl:call-template name="typeofdefine"/>
146 </xsl:for-each>
147 </xsl:for-each>
148 </xsl:template>
150 <xsl:template name="generatevalueresource">
151 <xsl:variable name="name" select="@name"/>
152 <xsl:variable name="ns_id" select="generate-id(ancestor::namespace)"/>
153 <resource>
154 <xsl:attribute name="name">
155 <xsl:value-of select="@name"/>
156 </xsl:attribute>
157 <xsl:attribute name="resource">Value</xsl:attribute>
158 <xsl:attribute name="generated">yes</xsl:attribute>
159 <xsl:for-each select="key('resourcetags', @name)[generate-id(ancestor::namespace) = $ns_id]">
160 <xsl:attribute name="tag">
161 <xsl:value-of select="."/>
162 </xsl:attribute>
163 </xsl:for-each>
164 <xsl:for-each select=".//rng:attribute">
165 <xsl:variable name="type">
166 <xsl:choose>
167 <xsl:when test="rng:ref[@name='ST_OnOff']">
168 <xsl:text>Boolean</xsl:text>
169 </xsl:when>
170 <xsl:when test="rng:text">
171 <xsl:text>String</xsl:text>
172 </xsl:when>
173 <xsl:otherwise>
174 <xsl:call-template name="typeofattribute"/>
175 </xsl:otherwise>
176 </xsl:choose>
177 </xsl:variable>
178 <attribute>
179 <xsl:attribute name="name">
180 <xsl:value-of select="@name"/>
181 </xsl:attribute>
182 <xsl:attribute name="tokenid">
183 <xsl:text>ooxml:</xsl:text>
184 <xsl:value-of select="$name"/>
185 <xsl:text>_</xsl:text>
186 <xsl:value-of select="@name"/>
187 </xsl:attribute>
188 <xsl:attribute name="action">
189 <xsl:text>setValue</xsl:text>
190 </xsl:attribute>
191 </attribute>
192 <xsl:if test="string-length($type) > 0">
193 <action name="start">
194 <xsl:attribute name="action">
195 <xsl:text>setDefault</xsl:text>
196 <xsl:value-of select="$type"/>
197 <xsl:text>Value</xsl:text>
198 </xsl:attribute>
199 </action>
200 </xsl:if>
201 </xsl:for-each>
202 </resource>
203 </xsl:template>
205 <xsl:template match="namespace">
206 <xsl:variable name="nsid" select="generate-id(.)"/>
207 <xsl:element name="namespace">
208 <xsl:copy-of select="@*"/>
209 <xsl:copy-of select=".//start"/>
210 <xsl:copy-of select="./rng:grammar"/>
212 <xsl:for-each select=".//rng:define">
213 <xsl:variable name="resources" select="key('resources', @name)[generate-id(ancestor::namespace) = $nsid]"/>
214 <xsl:copy-of select="$resources"/>
215 <xsl:if test="count($resources) = 0">
216 <xsl:if test="substring(@name, 1, 3) = 'CT_'">
217 <xsl:if test="./rng:attribute[@name='val']">
218 <xsl:call-template name="generatevalueresource"/>
219 </xsl:if>
220 </xsl:if>
221 <xsl:if test="substring(@name, 1, 3) = 'ST_'">
222 <xsl:if test="./rng:data[@type='int']">
223 <xsl:call-template name="generateresource">
224 <xsl:with-param name="resource">Integer</xsl:with-param>
225 </xsl:call-template>
226 </xsl:if>
227 <xsl:if test="./rng:data[@type='integer']">
228 <xsl:call-template name="generateresource">
229 <xsl:with-param name="resource">Integer</xsl:with-param>
230 </xsl:call-template>
231 </xsl:if>
232 <xsl:if test="./rng:data[@type='long']">
233 <xsl:call-template name="generateresource">
234 <xsl:with-param name="resource">Integer</xsl:with-param>
235 </xsl:call-template>
236 </xsl:if>
237 <xsl:if test="./rng:data[@type='unsignedInt']">
238 <xsl:call-template name="generateresource">
239 <xsl:with-param name="resource">Integer</xsl:with-param>
240 </xsl:call-template>
241 </xsl:if>
242 <xsl:if test="./rng:data[@type='unsignedLong']">
243 <xsl:call-template name="generateresource">
244 <xsl:with-param name="resource">Integer</xsl:with-param>
245 </xsl:call-template>
246 </xsl:if>
247 <xsl:if test="./rng:data[@type='boolean']">
248 <xsl:call-template name="generateresource">
249 <xsl:with-param name="resource">Boolean</xsl:with-param>
250 </xsl:call-template>
251 </xsl:if>
252 <xsl:if test="./rng:data[@type='token']">
253 <xsl:call-template name="generateresource">
254 <xsl:with-param name="resource">String</xsl:with-param>
255 </xsl:call-template>
256 </xsl:if>
257 <xsl:if test="./rng:data[@type='string']">
258 <xsl:call-template name="generateresource">
259 <xsl:with-param name="resource">String</xsl:with-param>
260 </xsl:call-template>
261 </xsl:if>
262 <xsl:if test="./rng:data[@type='dateTime']">
263 <xsl:call-template name="generateresource">
264 <xsl:with-param name="resource">String</xsl:with-param>
265 </xsl:call-template>
266 </xsl:if>
267 <xsl:if test="./rng:data[@type='hexBinary']">
268 <xsl:call-template name="generateresource">
269 <xsl:with-param name="resource">Hex</xsl:with-param>
270 </xsl:call-template>
271 </xsl:if>
272 <xsl:if test="./rng:list">
273 <xsl:call-template name="resourcevalues"/>
274 </xsl:if>
275 </xsl:if>
276 </xsl:if>
277 </xsl:for-each>
278 </xsl:element>
279 </xsl:template>
281 <xsl:template match="namespace-alias">
282 <namespace-alias>
283 <xsl:for-each select="@*">
284 <xsl:copy-of select="."/>
285 </xsl:for-each>
286 </namespace-alias>
287 </xsl:template>
289 <xsl:template match="token">
290 <token>
291 <xsl:for-each select="@*">
292 <xsl:copy-of select="."/>
293 </xsl:for-each>
294 </token>
295 </xsl:template>
297 <xsl:template match="fasttoken">
298 <xsl:copy-of select="."/>
299 </xsl:template>
301 <xsl:template match="/">
302 <model>
303 <xsl:apply-templates select=".//namespace-alias">
304 <xsl:sort select="@id" data-type="number"/>
305 </xsl:apply-templates>
306 <xsl:apply-templates select=".//token"/>
307 <xsl:apply-templates select=".//fasttoken"/>
308 <xsl:apply-templates select=".//namespace"/>
309 </model>
310 </xsl:template>
311 </xsl:stylesheet>