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 .
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"
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"/>
40 <xsl:attribute name=
"resource">
41 <xsl:value-of select=
"$resource"/>
43 <xsl:attribute name=
"generated">
44 <xsl:text>yes
</xsl:text>
46 <xsl:for-each select=
"key('resourcetags', @name)">
47 <xsl:attribute name=
"tag">
48 <xsl:value-of select=
"."/>
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"/>
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=
"."/>
70 <xsl:for-each select=
".//rng:value">
71 <xsl:element name=
"value">
72 <xsl:attribute name=
"name">
73 <xsl:value-of select=
"translate(., '-+ ,', 'mp__')"/>
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__')"/>
83 <xsl:value-of select=
"."/>
89 <xsl:template name=
"typeofdefine">
90 <xsl:for-each select=
"rng:data">
92 <xsl:when test=
"@type='base64Binary'">
93 <xsl:text>String
</xsl:text>
95 <xsl:when test=
"@type='boolean'">
96 <xsl:text>Boolean
</xsl:text>
98 <xsl:when test=
"@type='byte'">
99 <xsl:text>Integer
</xsl:text>
101 <xsl:when test=
"@type='dateTime'">
102 <xsl:text>String
</xsl:text>
104 <xsl:when test=
"@type='decimal'">
105 <xsl:text>Integer
</xsl:text>
107 <xsl:when test=
"@type='float'">
108 <xsl:text>Float
</xsl:text>
110 <xsl:when test=
"@type='hexBinary'">
111 <xsl:text>Hex
</xsl:text>
113 <xsl:when test=
"@type='int'">
114 <xsl:text>Integer
</xsl:text>
116 <xsl:when test=
"@type='integer'">
117 <xsl:text>Integer
</xsl:text>
119 <xsl:when test=
"@type='positiveInteger'">
120 <xsl:text>Integer
</xsl:text>
122 <xsl:when test=
"@type='string'">
123 <xsl:text>String
</xsl:text>
125 <xsl:when test=
"@type='token'">
126 <xsl:text>Integer
</xsl:text>
128 <xsl:when test=
"@type='unsignedInt'">
129 <xsl:text>Integer
</xsl:text>
131 <xsl:when test=
"@type='unsignedLong'">
132 <xsl:text>Integer
</xsl:text>
135 <xsl:text>Unknown
</xsl:text>
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"/>
150 <xsl:template name=
"generatevalueresource">
151 <xsl:variable name=
"name" select=
"@name"/>
152 <xsl:variable name=
"ns_id" select=
"generate-id(ancestor::namespace)"/>
154 <xsl:attribute name=
"name">
155 <xsl:value-of select=
"@name"/>
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=
"."/>
164 <xsl:for-each select=
".//rng:attribute">
165 <xsl:variable name=
"type">
167 <xsl:when test=
"rng:ref[@name='ST_OnOff']">
168 <xsl:text>Boolean
</xsl:text>
170 <xsl:when test=
"rng:text">
171 <xsl:text>String
</xsl:text>
174 <xsl:call-template name=
"typeofattribute"/>
179 <xsl:attribute name=
"name">
180 <xsl:value-of select=
"@name"/>
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"/>
188 <xsl:attribute name=
"action">
189 <xsl:text>setValue
</xsl:text>
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>
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"/>
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>
227 <xsl:if test=
"./rng:data[@type='integer']">
228 <xsl:call-template name=
"generateresource">
229 <xsl:with-param name=
"resource">Integer
</xsl:with-param>
232 <xsl:if test=
"./rng:data[@type='long']">
233 <xsl:call-template name=
"generateresource">
234 <xsl:with-param name=
"resource">Integer
</xsl:with-param>
237 <xsl:if test=
"./rng:data[@type='unsignedInt']">
238 <xsl:call-template name=
"generateresource">
239 <xsl:with-param name=
"resource">Integer
</xsl:with-param>
242 <xsl:if test=
"./rng:data[@type='unsignedLong']">
243 <xsl:call-template name=
"generateresource">
244 <xsl:with-param name=
"resource">Integer
</xsl:with-param>
247 <xsl:if test=
"./rng:data[@type='boolean']">
248 <xsl:call-template name=
"generateresource">
249 <xsl:with-param name=
"resource">Boolean
</xsl:with-param>
252 <xsl:if test=
"./rng:data[@type='token']">
253 <xsl:call-template name=
"generateresource">
254 <xsl:with-param name=
"resource">String
</xsl:with-param>
257 <xsl:if test=
"./rng:data[@type='string']">
258 <xsl:call-template name=
"generateresource">
259 <xsl:with-param name=
"resource">String
</xsl:with-param>
262 <xsl:if test=
"./rng:data[@type='dateTime']">
263 <xsl:call-template name=
"generateresource">
264 <xsl:with-param name=
"resource">String
</xsl:with-param>
267 <xsl:if test=
"./rng:data[@type='hexBinary']">
268 <xsl:call-template name=
"generateresource">
269 <xsl:with-param name=
"resource">Hex
</xsl:with-param>
272 <xsl:if test=
"./rng:list">
273 <xsl:call-template name=
"resourcevalues"/>
281 <xsl:template match=
"namespace-alias">
283 <xsl:for-each select=
"@*">
284 <xsl:copy-of select=
"."/>
289 <xsl:template match=
"token">
291 <xsl:for-each select=
"@*">
292 <xsl:copy-of select=
"."/>
297 <xsl:template match=
"fasttoken">
298 <xsl:copy-of select=
"."/>
301 <xsl:template match=
"/">
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"/>