1<!--***********************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 ***********************************************************-->
21<xsl:stylesheet
22    version="1.0"
23    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
24    xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
25    xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
26    xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
27    xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
28    xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
29    xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
30    xmlns:xlink="http://www.w3.org/1999/xlink"
31    xmlns:dc="http://purl.org/dc/elements/1.1/"
32    xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
33    xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
34    xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
35    xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
36    xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
37    xmlns:math="http://www.w3.org/1998/Math/MathML"
38    xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
39    xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
40    xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
41    xmlns:ooo="http://openoffice.org/2004/office"
42    xmlns:ooow="http://openoffice.org/2004/writer"
43    xmlns:oooc="http://openoffice.org/2004/calc"
44    xmlns:dom="http://www.w3.org/2001/xml-events"
45    xmlns:xforms="http://www.w3.org/2002/xforms"
46    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
47    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
49    xmlns:rng="http://relaxng.org/ns/structure/1.0"
50    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
51    xmlns:xalan="http://xml.apache.org/xalan"
52    xmlns:UML = 'org.omg.xmi.namespace.UML'
53    xmlns:common="http://exslt.org/common"
54    exclude-result-prefixes = "xalan"
55    xml:space="default">
56
57<!--
58     KEYS
59-->
60<xsl:key name="context-resource"
61         match="resource" use="@name"/>
62
63<xsl:key name="tokenids" match="@tokenid|@sendtokenid" use="."/>
64
65<xsl:key name="actions" match="/model/namespace/resource/action"
66    use="@name"/>
67
68<xsl:key name="definename" match="//rng:define" use="@name"/>
69
70<xsl:key name="resources" match="/model/namespace/resource" use="@resource"/>
71
72<xsl:key name="value-with-content" match="//rng:value"
73         use="text()"/>
74
75<xsl:key name="same-token-name" match="rng:element|rng:attribute" use="@localname"/>
76
77<!-- license header -->
78<xsl:template name="licenseheader">
79  <xsl:text>
80/*
81
82    THIS FILE IS GENERATED AUTOMATICALLY! DO NOT EDIT!
83
84*/
85&#xa;</xsl:text>
86</xsl:template>
87
88<!--
89IDENTIFIERs
90-->
91
92<!--
93
94generates token identifer for a namespace
95
96NN_<namespace/@name>
97
98-->
99<xsl:template name="fastnamespace">
100  <xsl:if test="string-length(@prefix) > 0">
101    <xsl:text>NS_</xsl:text>
102    <xsl:value-of select="@prefix"/>
103  </xsl:if>
104</xsl:template>
105
106<!--
107
108generates local part of token identifier for a rng:define
109
110OOXML_<rng:define/@localname>
111
112-->
113<xsl:template name="fastlocalname">
114  <xsl:text>OOXML_</xsl:text>
115  <xsl:value-of select="@localname"/>
116</xsl:template>
117
118<!--
119
120generates identifier for a token
121
122-->
123<xsl:template name="fasttoken">
124  <xsl:variable name="ns">
125    <xsl:call-template name="fastnamespace"/>
126  </xsl:variable>
127  <xsl:if test="string-length($ns) > 0">
128    <xsl:value-of select="$ns"/>
129    <xsl:text>|</xsl:text>
130  </xsl:if>
131  <xsl:call-template name="fastlocalname"/>
132</xsl:template>
133
134<!-- generates identifier for a namespace
135
136NN_<namespace/@name>
137
138-->
139<xsl:template name="idfornamespace">
140    <xsl:text>NN_</xsl:text>
141    <xsl:value-of select="translate(@name, '-', '_')"/>
142</xsl:template>
143
144<!-- generates local part of identier for rng:define
145
146DEFINE_<rng:define/@name>
147
148-->
149<xsl:template name="localidfordefine">
150    <xsl:text>DEFINE_</xsl:text>
151    <xsl:value-of select="@name"/>
152</xsl:template>
153
154<!-- generates id for a rng:define
155
156NN_<namespace/@name> | DEFINE_<rng:define/@name>
157
158-->
159<xsl:template name="idfordefine">
160    <xsl:for-each select="ancestor::namespace">
161        <xsl:call-template name="idfornamespace"/>
162    </xsl:for-each>
163    <xsl:text>|</xsl:text>
164    <xsl:call-template name="localidfordefine"/>
165</xsl:template>
166
167<!--
168
169creates case label for a rng:define:
170
171case NN_<namesapce/@name> | DEFINE_<rng:define/@name>:
172
173-->
174<xsl:template name="caselabeldefine">
175  <xsl:text>case </xsl:text>
176  <xsl:call-template name="idfordefine"/>
177  <xsl:text>:</xsl:text>
178</xsl:template>
179
180<!--
181    Generates name for a value string.
182
183    Value strings are possible values for attributes in OOXML.
184
185    @param string    the string as present in the according <rng:value>
186-->
187<xsl:template name="valuestringname">
188  <xsl:param name="string"/>
189  <xsl:text>OOXMLValueString_</xsl:text>
190  <xsl:value-of select="translate($string, '-+ ,', 'mp__')"/>
191</xsl:template>
192
193<!--
194    Generates qname for id.
195
196    @param id     the id to generate qname for
197
198    If id is of format <prefix>:<localname> the result is
199
200    NS_<prefix>::LN_<localname>
201
202    If id does not contain ":" the result is just id.
203-->
204<xsl:template name='idtoqname'>
205  <xsl:param name='id'/>
206  <xsl:choose>
207    <xsl:when test="contains($id, ':')">
208      <xsl:text>NS_</xsl:text>
209      <xsl:value-of select='substring-before($id, ":")'/>
210      <xsl:text>::LN_</xsl:text>
211      <xsl:value-of select='substring-after($id, ":")'/>
212    </xsl:when>
213    <xsl:otherwise>
214      <xsl:value-of select="$id"/>
215    </xsl:otherwise>
216  </xsl:choose>
217</xsl:template>
218
219<!--
220    Returns the identifier for a namespace.
221
222NS_<namespace/@alias>
223
224-->
225<xsl:template name="namespaceid">
226  <xsl:text>NS_</xsl:text>
227  <xsl:value-of select="@alias"/>
228</xsl:template>
229
230<!--
231    Returns the value of the @resource attribute of the <resource>
232    node according to the current <define>.
233-->
234<xsl:template name="contextresource">
235  <xsl:variable name="name" select="@name"/>
236  <xsl:variable name="nsid" select="generate-id(ancestor::namespace)"/>
237  <xsl:variable name="resourcesamens">
238    <xsl:for-each select="key('context-resource', @name)">
239      <xsl:if test="generate-id(ancestor::namespace) = $nsid">
240	<xsl:value-of select="@resource"/>
241      </xsl:if>
242    </xsl:for-each>
243  </xsl:variable>
244  <xsl:choose>
245    <xsl:when test="$name='BUILT_IN_ANY_TYPE'">
246      <xsl:text>Any</xsl:text>
247    </xsl:when>
248    <xsl:when test="string-length($resourcesamens) = 0">
249      <xsl:for-each select="key('context-resource', @name)[1]">
250	<xsl:value-of select="@resource"/>
251      </xsl:for-each>
252    </xsl:when>
253    <xsl:otherwise>
254      <xsl:value-of select="$resourcesamens"/>
255    </xsl:otherwise>
256  </xsl:choose>
257</xsl:template>
258
259<xsl:template name="idforref">
260    <xsl:variable name="name" select="@name"/>
261    <xsl:variable name="result1">
262      <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$name]">
263	<xsl:call-template name="idfordefine"/>
264      </xsl:for-each>
265    </xsl:variable>
266    <xsl:choose>
267      <xsl:when test="$name='BUILT_IN_ANY_TYPE'">
268	<xsl:text>0</xsl:text>
269      </xsl:when>
270      <xsl:when test="string-length($result1) = 0">
271	<xsl:for-each select="(ancestor::model/namespace/rng:grammar/rng:define[@name=$name])[1]">
272	  <xsl:call-template name="idfordefine"/>
273	</xsl:for-each>
274      </xsl:when>
275      <xsl:otherwise>
276	<xsl:value-of select="$result1"/>
277      </xsl:otherwise>
278    </xsl:choose>
279</xsl:template>
280
281<!-- factoryclassname -->
282<xsl:template name="factoryclassname">
283    <xsl:text>OOXMLFactory_</xsl:text>
284    <xsl:value-of select="translate(@name, '-', '_')"/>
285</xsl:template>
286
287<xsl:template name="factoryincludes">
288    <xsl:for-each select="/model/namespace">
289        <xsl:text>
290#include "OOXMLFactory_</xsl:text>
291        <xsl:value-of select="@name"/>
292        <xsl:text>.hxx"</xsl:text>
293    </xsl:for-each>
294</xsl:template>
295
296<xsl:template name="factorydefineiddecls">
297    <xsl:for-each select="//rng:define">
298        <xsl:sort select="@name"/>
299        <xsl:if test="generate-id(key('definename', @name)[1]) = generate-id(.)">
300            <xsl:text>
301extern const Id </xsl:text>
302            <xsl:call-template name="localidfordefine"/>
303            <xsl:text>;</xsl:text>
304        </xsl:if>
305    </xsl:for-each>
306</xsl:template>
307
308<xsl:template name="factorydefineidimpls">
309    <xsl:for-each select="//rng:define">
310        <xsl:sort select="@name"/>
311        <xsl:if test="generate-id(key('definename', @name)[1]) = generate-id(.)">
312            <xsl:text>
313const Id </xsl:text>
314            <xsl:call-template name="localidfordefine"/>
315            <xsl:text> = </xsl:text>
316            <xsl:value-of select="position()"/>
317            <xsl:text>;</xsl:text>
318        </xsl:if>
319    </xsl:for-each>
320</xsl:template>
321
322<xsl:template name="resources">
323    <xsl:for-each select="/model/namespace/resource">
324        <xsl:if test="generate-id(key('resources', @resource)[1])=generate-id(.)">
325            <xsl:text>RT_</xsl:text>
326            <xsl:value-of select="@resource"/>
327            <xsl:text>,&#xa;</xsl:text>
328        </xsl:if>
329    </xsl:for-each>
330</xsl:template>
331
332</xsl:stylesheet>
333