bump product version to 4.1.6.2
[LibreOffice.git] / writerfilter / source / ooxml / factorytools.xsl
blob3d6ce8b2782697d6fd4a033e15f93c892d8a8220
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:xalan="http://xml.apache.org/xalan"
49 xmlns:UML = 'org.omg.xmi.namespace.UML'
50 xmlns:common="http://exslt.org/common"
51 exclude-result-prefixes = "xalan"
52 xml:space="default">
54 <!--
55 KEYS
56 -->
57 <xsl:key name="context-resource"
58 match="resource" use="@name"/>
60 <xsl:key name="tokenids" match="@tokenid|@sendtokenid" use="."/>
62 <xsl:key name="actions" match="/model/namespace/resource/action"
63 use="@name"/>
65 <xsl:key name="definename" match="//rng:define" use="@name"/>
67 <xsl:key name="resources" match="/model/namespace/resource" use="@resource"/>
69 <xsl:key name="value-with-content" match="//rng:value"
70 use="text()"/>
72 <xsl:key name="same-token-name" match="rng:element|rng:attribute" use="@localname"/>
74 <!-- license header -->
75 <xsl:template name="licenseheader">
76 <xsl:text>
77 /*
79 THIS FILE IS GENERATED AUTOMATICALLY! DO NOT EDIT!
82 &#xa;</xsl:text>
83 </xsl:template>
85 <!--
86 IDENTIFIERs
87 -->
89 <!--
91 generates token identifer for a namespace
93 NN_<namespace/@name>
95 -->
96 <xsl:template name="fastnamespace">
97 <xsl:if test="string-length(@prefix) > 0">
98 <xsl:text>NS_</xsl:text>
99 <xsl:value-of select="@prefix"/>
100 </xsl:if>
101 </xsl:template>
103 <!--
105 generates local part of token identifier for a rng:define
107 OOXML_<rng:define/@localname>
110 <xsl:template name="fastlocalname">
111 <xsl:text>OOXML_</xsl:text>
112 <xsl:value-of select="@localname"/>
113 </xsl:template>
115 <!--
117 generates identifier for a token
120 <xsl:template name="fasttoken">
121 <xsl:variable name="ns">
122 <xsl:call-template name="fastnamespace"/>
123 </xsl:variable>
124 <xsl:if test="string-length($ns) > 0">
125 <xsl:value-of select="$ns"/>
126 <xsl:text>|</xsl:text>
127 </xsl:if>
128 <xsl:call-template name="fastlocalname"/>
129 </xsl:template>
131 <!-- generates identifier for a namespace
133 NN_<namespace/@name>
136 <xsl:template name="idfornamespace">
137 <xsl:text>NN_</xsl:text>
138 <xsl:value-of select="translate(@name, '-', '_')"/>
139 </xsl:template>
141 <!-- generates local part of identier for rng:define
143 DEFINE_<rng:define/@name>
146 <xsl:template name="localidfordefine">
147 <xsl:text>DEFINE_</xsl:text>
148 <xsl:value-of select="@name"/>
149 </xsl:template>
151 <!-- generates id for a rng:define
153 NN_<namespace/@name> | DEFINE_<rng:define/@name>
156 <xsl:template name="idfordefine">
157 <xsl:for-each select="ancestor::namespace">
158 <xsl:call-template name="idfornamespace"/>
159 </xsl:for-each>
160 <xsl:text>|</xsl:text>
161 <xsl:call-template name="localidfordefine"/>
162 </xsl:template>
164 <!--
166 creates case label for a rng:define:
168 case NN_<namesapce/@name> | DEFINE_<rng:define/@name>:
171 <xsl:template name="caselabeldefine">
172 <xsl:text>case </xsl:text>
173 <xsl:call-template name="idfordefine"/>
174 <xsl:text>:</xsl:text>
175 </xsl:template>
177 <!--
178 Generates name for a value string.
180 Value strings are possible values for attributes in OOXML.
182 @param string the string as present in the according <rng:value>
184 <xsl:template name="valuestringname">
185 <xsl:param name="string"/>
186 <xsl:text>OOXMLValueString_</xsl:text>
187 <xsl:value-of select="translate($string, '-+ ,', 'mp__')"/>
188 </xsl:template>
190 <!--
191 Generates qname for id.
193 @param id the id to generate qname for
195 If id is of format <prefix>:<localname> the result is
197 NS_<prefix>::LN_<localname>
199 If id does not contain ":" the result is just id.
201 <xsl:template name='idtoqname'>
202 <xsl:param name='id'/>
203 <xsl:choose>
204 <xsl:when test="contains($id, ':')">
205 <xsl:text>NS_</xsl:text>
206 <xsl:value-of select='substring-before($id, ":")'/>
207 <xsl:text>::LN_</xsl:text>
208 <xsl:value-of select='substring-after($id, ":")'/>
209 </xsl:when>
210 <xsl:otherwise>
211 <xsl:value-of select="$id"/>
212 </xsl:otherwise>
213 </xsl:choose>
214 </xsl:template>
216 <!--
217 Returns the identifier for a namespace.
219 NS_<namespace/@alias>
222 <xsl:template name="namespaceid">
223 <xsl:text>NS_</xsl:text>
224 <xsl:value-of select="@alias"/>
225 </xsl:template>
227 <!--
228 Returns the value of the @resource attribute of the <resource>
229 node according to the current <define>.
231 <xsl:template name="contextresource">
232 <xsl:variable name="name" select="@name"/>
233 <xsl:variable name="nsid" select="generate-id(ancestor::namespace)"/>
234 <xsl:variable name="resourcesamens">
235 <xsl:for-each select="key('context-resource', @name)">
236 <xsl:if test="generate-id(ancestor::namespace) = $nsid">
237 <xsl:value-of select="@resource"/>
238 </xsl:if>
239 </xsl:for-each>
240 </xsl:variable>
241 <xsl:choose>
242 <xsl:when test="$name='BUILT_IN_ANY_TYPE'">
243 <xsl:text>Any</xsl:text>
244 </xsl:when>
245 <xsl:when test="string-length($resourcesamens) = 0">
246 <xsl:for-each select="key('context-resource', @name)[1]">
247 <xsl:value-of select="@resource"/>
248 </xsl:for-each>
249 </xsl:when>
250 <xsl:otherwise>
251 <xsl:value-of select="$resourcesamens"/>
252 </xsl:otherwise>
253 </xsl:choose>
254 </xsl:template>
256 <xsl:template name="idforref">
257 <xsl:variable name="name" select="@name"/>
258 <xsl:variable name="result1">
259 <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
260 <xsl:call-template name="idfordefine"/>
261 </xsl:for-each>
262 </xsl:variable>
263 <xsl:choose>
264 <xsl:when test="$name='BUILT_IN_ANY_TYPE'">
265 <xsl:text>0</xsl:text>
266 </xsl:when>
267 <xsl:when test="string-length($result1) = 0">
268 <xsl:for-each select="(ancestor::model/namespace/rng:grammar/rng:define[@name=$name])[1]">
269 <xsl:call-template name="idfordefine"/>
270 </xsl:for-each>
271 </xsl:when>
272 <xsl:otherwise>
273 <xsl:value-of select="$result1"/>
274 </xsl:otherwise>
275 </xsl:choose>
276 </xsl:template>
278 <!-- factoryclassname -->
279 <xsl:template name="factoryclassname">
280 <xsl:text>OOXMLFactory_</xsl:text>
281 <xsl:value-of select="translate(@name, '-', '_')"/>
282 </xsl:template>
284 <xsl:template name="factoryincludes">
285 <xsl:for-each select="/model/namespace">
286 <xsl:text>
287 #include "OOXMLFactory_</xsl:text>
288 <xsl:value-of select="@name"/>
289 <xsl:text>.hxx"</xsl:text>
290 </xsl:for-each>
291 </xsl:template>
293 <xsl:template name="factorydefineiddecls">
294 <xsl:for-each select="//rng:define">
295 <xsl:sort select="@name"/>
296 <xsl:if test="generate-id(key('definename', @name)[1]) = generate-id(.)">
297 <xsl:text>
298 extern const Id </xsl:text>
299 <xsl:call-template name="localidfordefine"/>
300 <xsl:text>;</xsl:text>
301 </xsl:if>
302 </xsl:for-each>
303 </xsl:template>
305 <xsl:template name="factorydefineidimpls">
306 <xsl:for-each select="//rng:define">
307 <xsl:sort select="@name"/>
308 <xsl:if test="generate-id(key('definename', @name)[1]) = generate-id(.)">
309 <xsl:text>
310 const Id </xsl:text>
311 <xsl:call-template name="localidfordefine"/>
312 <xsl:text> = </xsl:text>
313 <xsl:value-of select="position()"/>
314 <xsl:text>;</xsl:text>
315 </xsl:if>
316 </xsl:for-each>
317 </xsl:template>
319 <xsl:template name="resources">
320 <xsl:for-each select="/model/namespace/resource">
321 <xsl:if test="generate-id(key('resources', @resource)[1])=generate-id(.)">
322 <xsl:text>RT_</xsl:text>
323 <xsl:value-of select="@resource"/>
324 <xsl:text>,&#xa;</xsl:text>
325 </xsl:if>
326 </xsl:for-each>
327 </xsl:template>
329 </xsl:stylesheet>