2 /*************************************************************************
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 Copyright 2008 by Sun Microsystems, Inc.
8 OpenOffice.org - a multi-platform office productivity suite
10 $RCSfile: modelpreprocess.xsl,v $
14 This file is part of OpenOffice.org.
16 OpenOffice.org is free software: you can redistribute it and/or modify
17 it under the terms of the GNU Lesser General Public License version 3
18 only, as published by the Free Software Foundation.
20 OpenOffice.org is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU Lesser General Public License version 3 for more details
24 (a copy is included in the LICENSE file that accompanied this code).
26 You should have received a copy of the GNU Lesser General Public License
27 version 3 along with OpenOffice.org. If not, see
28 <http://www.openoffice.org/license.html>
29 for a copy of the LGPLv3 License.
31 ************************************************************************/
36 xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
37 xmlns:
office=
"urn:oasis:names:tc:opendocument:xmlns:office:1.0"
38 xmlns:
style=
"urn:oasis:names:tc:opendocument:xmlns:style:1.0"
39 xmlns:
text=
"urn:oasis:names:tc:opendocument:xmlns:text:1.0"
40 xmlns:
table=
"urn:oasis:names:tc:opendocument:xmlns:table:1.0"
41 xmlns:
draw=
"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
42 xmlns:
fo=
"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
43 xmlns:
xlink=
"http://www.w3.org/1999/xlink"
44 xmlns:
dc=
"http://purl.org/dc/elements/1.1/"
45 xmlns:
meta=
"urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
46 xmlns:
number=
"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
47 xmlns:
svg=
"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
48 xmlns:
chart=
"urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
49 xmlns:
dr3d=
"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
50 xmlns:
math=
"http://www.w3.org/1998/Math/MathML"
51 xmlns:
form=
"urn:oasis:names:tc:opendocument:xmlns:form:1.0"
52 xmlns:
script=
"urn:oasis:names:tc:opendocument:xmlns:script:1.0"
53 xmlns:
config=
"urn:oasis:names:tc:opendocument:xmlns:config:1.0"
54 xmlns:
ooo=
"http://openoffice.org/2004/office"
55 xmlns:
ooow=
"http://openoffice.org/2004/writer"
56 xmlns:
oooc=
"http://openoffice.org/2004/calc"
57 xmlns:
dom=
"http://www.w3.org/2001/xml-events"
58 xmlns:
xforms=
"http://www.w3.org/2002/xforms"
59 xmlns:
xsd=
"http://www.w3.org/2001/XMLSchema"
60 xmlns:
xsi=
"http://www.w3.org/2001/XMLSchema-instance"
61 xmlns:
rdf=
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"
62 xmlns:
rng=
"http://relaxng.org/ns/structure/1.0"
63 xmlns:
rdfs=
"http://www.w3.org/2000/01/rdf-schema#"
64 xmlns:UML = 'org.omg.xmi.namespace.UML' xml:
space=
"default">
65 <xsl:output method=
"xml" />
67 <!--<xsl:include href="resourcestools.xsl"/>-->
69 <xsl:key name=
"namespace-aliases" match=
"//namespace-alias" use=
"@name"/>
71 <xsl:template match=
"/">
72 <xsl:apply-templates/>
75 <xsl:template name=
"prefixfromurl">
76 <xsl:param name=
"url"/>
77 <xsl:variable name=
"prefix" select=
"key('namespace-aliases', $url)/@alias"/>
79 <xsl:when test=
"string-length($prefix) > 0">
80 <xsl:value-of select=
"$prefix"/>
83 <xsl:value-of select=
"translate(substring-after($url, 'http://'), '/.', '__')"/>
88 <xsl:template name=
"prefixforgrammar">
89 <xsl:variable name=
"ns" select=
"ancestor::namespace/rng:grammar/@ns"/>
90 <xsl:variable name=
"prefix" select=
"key('namespace-aliases', $ns)/@alias"/>
92 <xsl:when test=
"string-length($prefix) > 0">
93 <xsl:value-of select=
"$prefix"/>
96 <xsl:call-template name=
"prefixfromurl">
97 <xsl:with-param name=
"url" select=
"$ns"/>
103 <xsl:template name=
"nsforgrammar">
104 <xsl:value-of select=
"ancestor::namespace/rng:grammar/@ns"/>
107 <xsl:template match=
"rng:element[@name] | rng:attribute[@name] | element | attribute">
108 <xsl:variable name=
"prefix">
110 <xsl:when test=
"contains(@name, ':')">
111 <xsl:variable name=
"myname" select=
"@name"/>
112 <xsl:call-template name=
"prefixfromurl">
113 <xsl:with-param name=
"url" select=
"string(namespace::*[local-name(.) = substring-before($myname, ':')])"/>
116 <xsl:when test=
"name(.)='attribute'">
117 <xsl:if test=
"ancestor::rng:grammar/@attributeFormDefault='qualified'">
118 <xsl:call-template name=
"prefixforgrammar"/>
122 <xsl:call-template name=
"prefixforgrammar"/>
126 <xsl:variable name=
"ns">
128 <xsl:when test=
"contains(@name, ':')">
129 <xsl:variable name=
"myname" select=
"@name"/>
130 <xsl:value-of select=
"string(namespace::*[local-name(.) = substring-before($myname, ':')])"/>
132 <xsl:when test=
"name(.)='attribute'">
133 <xsl:if test=
"ancestor::rng:grammar/@attributeFormDefault='qualified'">
134 <xsl:call-template name=
"nsforgrammar"/>
138 <xsl:call-template name=
"nsforgrammar"/>
142 <xsl:variable name=
"localname">
144 <xsl:when test=
"contains(@name, ':')">
145 <xsl:value-of select=
"substring-after(@name, ':')"/>
148 <xsl:value-of select=
"@name"/>
153 <xsl:apply-templates select=
"@*"/>
154 <xsl:attribute name=
"enumname">
155 <xsl:if test=
"string-length($prefix) > 0">
156 <xsl:value-of select=
"$prefix"/>
157 <xsl:text>:
</xsl:text>
159 <xsl:value-of select=
"$localname"/>
161 <xsl:attribute name=
"qname">
162 <xsl:if test=
"string-length($ns) > 0">
163 <xsl:value-of select=
"$ns"/>
164 <xsl:text>:
</xsl:text>
166 <xsl:value-of select=
"$localname"/>
168 <xsl:attribute name=
"prefix">
169 <xsl:value-of select=
"$prefix"/>
171 <xsl:attribute name=
"localname">
172 <xsl:value-of select=
"$localname"/>
174 <xsl:apply-templates/>
178 <xsl:template match=
"rng:grammar">
180 <xsl:apply-templates select=
"@*"/>
181 <xsl:attribute name=
"application">
182 <xsl:value-of select=
"substring-before(substring-after(@ns, 'http://schemas.openxmlformats.org/'), '/')"/>
184 <xsl:apply-templates/>
188 <xsl:template match=
"node()|@*">
190 <xsl:apply-templates select=
"@*"/>
191 <xsl:apply-templates/>
195 <xsl:template match=
"model">
197 <xsl:apply-templates select=
"@*"/>
198 <xsl:apply-templates/>
202 <xsl:template match=
"rng:define|rng:ref">
204 <xsl:apply-templates select=
"@*"/>
205 <xsl:attribute name=
"classfordefine">
206 <xsl:variable name=
"name" select=
"@name"/>
208 <xsl:when test=
"(starts-with(@name, 'CT_') or starts-with(@name, 'EG_') or starts-with(@name, 'AG_'))">1</xsl:when>
209 <xsl:when test=
"ancestor::namespace//start[@name=$name]">1</xsl:when>
210 <xsl:otherwise>0</xsl:otherwise>
213 <xsl:apply-templates/>
217 <xsl:template match=
"namespace">
218 <xsl:variable name=
"ns" select=
".//rng:grammar/@ns"/>
220 <xsl:apply-templates select=
"@*"/>
221 <xsl:attribute name=
"namespacealias">
222 <xsl:value-of select=
"key('namespace-aliases', $ns)/@alias"/>
224 <xsl:attribute name=
"prefix"><xsl:value-of select=
"translate(substring-after($ns, 'http://schemas.openxmlformats.org/'), '/-', '__')"/></xsl:attribute>
225 <xsl:apply-templates/>