update dev300-m58
[ooovba.git] / writerfilter / source / ooxml / modelpreprocess.xsl
blob51efa93f33f1535a0347feaadae479ac38aa6556
1 <!--
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 $
12 $Revision: 1.7 $
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 ************************************************************************/
33 -->
34 <xsl:stylesheet
35 version="1.0"
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/>
73 </xsl:template>
75 <xsl:template name="prefixfromurl">
76 <xsl:param name="url"/>
77 <xsl:variable name="prefix" select="key('namespace-aliases', $url)/@alias"/>
78 <xsl:choose>
79 <xsl:when test="string-length($prefix) > 0">
80 <xsl:value-of select="$prefix"/>
81 </xsl:when>
82 <xsl:otherwise>
83 <xsl:value-of select="translate(substring-after($url, 'http://'), '/.', '__')"/>
84 </xsl:otherwise>
85 </xsl:choose>
86 </xsl:template>
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"/>
91 <xsl:choose>
92 <xsl:when test="string-length($prefix) > 0">
93 <xsl:value-of select="$prefix"/>
94 </xsl:when>
95 <xsl:otherwise>
96 <xsl:call-template name="prefixfromurl">
97 <xsl:with-param name="url" select="$ns"/>
98 </xsl:call-template>
99 </xsl:otherwise>
100 </xsl:choose>
101 </xsl:template>
103 <xsl:template name="nsforgrammar">
104 <xsl:value-of select="ancestor::namespace/rng:grammar/@ns"/>
105 </xsl:template>
107 <xsl:template match="rng:element[@name] | rng:attribute[@name] | element | attribute">
108 <xsl:variable name="prefix">
109 <xsl:choose>
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, ':')])"/>
114 </xsl:call-template>
115 </xsl:when>
116 <xsl:when test="name(.)='attribute'">
117 <xsl:if test="ancestor::rng:grammar/@attributeFormDefault='qualified'">
118 <xsl:call-template name="prefixforgrammar"/>
119 </xsl:if>
120 </xsl:when>
121 <xsl:otherwise>
122 <xsl:call-template name="prefixforgrammar"/>
123 </xsl:otherwise>
124 </xsl:choose>
125 </xsl:variable>
126 <xsl:variable name="ns">
127 <xsl:choose>
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, ':')])"/>
131 </xsl:when>
132 <xsl:when test="name(.)='attribute'">
133 <xsl:if test="ancestor::rng:grammar/@attributeFormDefault='qualified'">
134 <xsl:call-template name="nsforgrammar"/>
135 </xsl:if>
136 </xsl:when>
137 <xsl:otherwise>
138 <xsl:call-template name="nsforgrammar"/>
139 </xsl:otherwise>
140 </xsl:choose>
141 </xsl:variable>
142 <xsl:variable name="localname">
143 <xsl:choose>
144 <xsl:when test="contains(@name, ':')">
145 <xsl:value-of select="substring-after(@name, ':')"/>
146 </xsl:when>
147 <xsl:otherwise>
148 <xsl:value-of select="@name"/>
149 </xsl:otherwise>
150 </xsl:choose>
151 </xsl:variable>
152 <xsl:copy>
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>
158 </xsl:if>
159 <xsl:value-of select="$localname"/>
160 </xsl:attribute>
161 <xsl:attribute name="qname">
162 <xsl:if test="string-length($ns) > 0">
163 <xsl:value-of select="$ns"/>
164 <xsl:text>:</xsl:text>
165 </xsl:if>
166 <xsl:value-of select="$localname"/>
167 </xsl:attribute>
168 <xsl:attribute name="prefix">
169 <xsl:value-of select="$prefix"/>
170 </xsl:attribute>
171 <xsl:attribute name="localname">
172 <xsl:value-of select="$localname"/>
173 </xsl:attribute>
174 <xsl:apply-templates/>
175 </xsl:copy>
176 </xsl:template>
178 <xsl:template match="rng:grammar">
179 <xsl:copy>
180 <xsl:apply-templates select="@*"/>
181 <xsl:attribute name="application">
182 <xsl:value-of select="substring-before(substring-after(@ns, 'http://schemas.openxmlformats.org/'), '/')"/>
183 </xsl:attribute>
184 <xsl:apply-templates/>
185 </xsl:copy>
186 </xsl:template>
188 <xsl:template match="node()|@*">
189 <xsl:copy>
190 <xsl:apply-templates select="@*"/>
191 <xsl:apply-templates/>
192 </xsl:copy>
193 </xsl:template>
195 <xsl:template match="model">
196 <xsl:copy>
197 <xsl:apply-templates select="@*"/>
198 <xsl:apply-templates/>
199 </xsl:copy>
200 </xsl:template>
202 <xsl:template match="rng:define|rng:ref">
203 <xsl:copy>
204 <xsl:apply-templates select="@*"/>
205 <xsl:attribute name="classfordefine">
206 <xsl:variable name="name" select="@name"/>
207 <xsl:choose>
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>
211 </xsl:choose>
212 </xsl:attribute>
213 <xsl:apply-templates/>
214 </xsl:copy>
215 </xsl:template>
217 <xsl:template match="namespace">
218 <xsl:variable name="ns" select=".//rng:grammar/@ns"/>
219 <xsl:copy>
220 <xsl:apply-templates select="@*"/>
221 <xsl:attribute name="namespacealias">
222 <xsl:value-of select="key('namespace-aliases', $ns)/@alias"/>
223 </xsl:attribute>
224 <xsl:attribute name="prefix"><xsl:value-of select="translate(substring-after($ns, 'http://schemas.openxmlformats.org/'), '/-', '__')"/></xsl:attribute>
225 <xsl:apply-templates/>
226 </xsl:copy>
227 </xsl:template>
228 </xsl:stylesheet>