update dev300-m58
[ooovba.git] / writerfilter / source / ooxml / modelcleanup.xsl
blob7817aac72522478101cf0f23061cc2edaafa3f1b
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: modelcleanup.xsl,v $
12 $Revision: 1.6 $
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:rng="http://relaxng.org/ns/structure/1.0"
38 xmlns:xalan="http://xml.apache.org/xalan"
39 exclude-result-prefixes = "xalan"
40 xml:indent="true">
41 <xsl:output method="xml" />
44 <xsl:key name="resources"
45 match="resource[not(@generated)]" use="@name" />
47 <xsl:template name="generateresource">
48 <xsl:param name="resource"/>
49 <xsl:element name="resource">
50 <xsl:attribute name="name">
51 <xsl:value-of select="@name"/>
52 </xsl:attribute>
53 <xsl:attribute name="resource">
54 <xsl:value-of select="$resource"/>
55 </xsl:attribute>
56 <xsl:attribute name="generated">
57 <xsl:text>yes</xsl:text>
58 </xsl:attribute>
59 </xsl:element>
60 </xsl:template>
62 <xsl:key name="nsaliases" match="//namespace-alias" use="@name"/>
64 <xsl:template name="resourcevalues">
65 <xsl:variable name="definename" select="@name"/>
66 <xsl:variable name="namespace" select="key('nsaliases', ancestor::namespace/rng:grammar/@ns)/@alias"/>
67 <xsl:element name="resource">
68 <xsl:attribute name="name">
69 <xsl:value-of select="@name"/>
70 </xsl:attribute>
71 <xsl:attribute name="resource">List</xsl:attribute>
72 <xsl:attribute name="generated">yes</xsl:attribute>
73 <xsl:for-each select=".//rng:value">
74 <xsl:element name="value">
75 <xsl:attribute name="name">
76 <xsl:value-of select="translate(., '-+ ,', 'mp__')"/>
77 </xsl:attribute>
78 <xsl:attribute name="tokenid">
79 <xsl:text>ooxml:Value_</xsl:text>
80 <xsl:value-of select="translate($namespace, '-', '_')"/>
81 <xsl:text>_</xsl:text>
82 <xsl:value-of select="$definename"/>
83 <xsl:text>_</xsl:text>
84 <xsl:value-of select="translate(., '-+ ,', 'mp__')"/>
85 </xsl:attribute>
86 <xsl:value-of select="."/>
87 </xsl:element>
88 </xsl:for-each>
89 </xsl:element>
90 </xsl:template>
92 <xsl:template match="namespace">
93 <xsl:variable name="nsid" select="generate-id(.)"/>
94 <xsl:element name="namespace">
95 <xsl:copy-of select="@*"/>
96 <xsl:copy-of select=".//start"/>
97 <xsl:copy-of select="./rng:grammar"/>
99 <xsl:for-each select=".//rng:define">
100 <xsl:variable name="resources" select="key('resources', @name)[generate-id(ancestor::namespace) = $nsid]"/>
101 <xsl:copy-of select="$resources"/>
102 <xsl:if test="count($resources) = 0">
103 <xsl:if test="substring(@name, 1, 3) = 'CT_'">
104 <xsl:if test="./rng:attribute[@name='val']/rng:text">
105 <xsl:call-template name="generateresource">
106 <xsl:with-param name="resource">StringValue</xsl:with-param>
107 </xsl:call-template>
108 </xsl:if>
109 </xsl:if>
110 <xsl:if test="substring(@name, 1, 3) = 'ST_'">
111 <xsl:if test="./rng:data[@type='int']">
112 <xsl:call-template name="generateresource">
113 <xsl:with-param name="resource">Integer</xsl:with-param>
114 </xsl:call-template>
115 </xsl:if>
116 <xsl:if test="./rng:data[@type='integer']">
117 <xsl:call-template name="generateresource">
118 <xsl:with-param name="resource">Integer</xsl:with-param>
119 </xsl:call-template>
120 </xsl:if>
121 <xsl:if test="./rng:data[@type='long']">
122 <xsl:call-template name="generateresource">
123 <xsl:with-param name="resource">Integer</xsl:with-param>
124 </xsl:call-template>
125 </xsl:if>
126 <xsl:if test="./rng:data[@type='unsignedInt']">
127 <xsl:call-template name="generateresource">
128 <xsl:with-param name="resource">Integer</xsl:with-param>
129 </xsl:call-template>
130 </xsl:if>
131 <xsl:if test="./rng:data[@type='unsignedLong']">
132 <xsl:call-template name="generateresource">
133 <xsl:with-param name="resource">Integer</xsl:with-param>
134 </xsl:call-template>
135 </xsl:if>
136 <xsl:if test="./rng:data[@type='boolean']">
137 <xsl:call-template name="generateresource">
138 <xsl:with-param name="resource">Boolean</xsl:with-param>
139 </xsl:call-template>
140 </xsl:if>
141 <xsl:if test="./rng:data[@type='token']">
142 <xsl:call-template name="generateresource">
143 <xsl:with-param name="resource">String</xsl:with-param>
144 </xsl:call-template>
145 </xsl:if>
146 <xsl:if test="./rng:data[@type='string']">
147 <xsl:call-template name="generateresource">
148 <xsl:with-param name="resource">String</xsl:with-param>
149 </xsl:call-template>
150 </xsl:if>
151 <xsl:if test="./rng:data[@type='dateTime']">
152 <xsl:call-template name="generateresource">
153 <xsl:with-param name="resource">String</xsl:with-param>
154 </xsl:call-template>
155 </xsl:if>
156 <xsl:if test="./rng:data[@type='hexBinary']">
157 <xsl:call-template name="generateresource">
158 <xsl:with-param name="resource">Hex</xsl:with-param>
159 </xsl:call-template>
160 </xsl:if>
161 <xsl:if test="./rng:list">
162 <xsl:call-template name="resourcevalues"/>
163 </xsl:if>
164 </xsl:if>
165 </xsl:if>
166 </xsl:for-each>
167 </xsl:element>
168 </xsl:template>
170 <xsl:template match="namespace-alias">
171 <namespace-alias>
172 <xsl:for-each select="@*">
173 <xsl:copy-of select="."/>
174 </xsl:for-each>
175 </namespace-alias>
176 </xsl:template>
178 <xsl:template match="token">
179 <token>
180 <xsl:for-each select="@*">
181 <xsl:copy-of select="."/>
182 </xsl:for-each>
183 </token>
184 </xsl:template>
186 <xsl:template match="fasttoken">
187 <xsl:copy-of select="."/>
188 </xsl:template>
190 <xsl:template match="/">
191 <model>
192 <xsl:apply-templates select=".//namespace-alias">
193 <xsl:sort select="@id" data-type="number"/>
194 </xsl:apply-templates>
195 <xsl:apply-templates select=".//token"/>
196 <xsl:apply-templates select=".//fasttoken"/>
197 <xsl:apply-templates select=".//namespace"/>
198 </model>
199 </xsl:template>
200 </xsl:stylesheet>