1 <?xml version=
"1.0" encoding=
"utf-8" standalone=
"yes" ?>
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: data_val.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 ************************************************************************ -->
33 <!-- ************************************************************************************** -->
34 <!-- * Transformation from New Format XCS & XCU to schema description *** -->
35 <!-- ************************************************************************************** -->
36 <xsl:transform version=
"1.0" xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
37 xmlns:
xsi=
"http://www.w3.org/1999/XMLSchema-instance"
38 xmlns:
xs=
"http://www.w3.org/2001/XMLSchema"
39 xmlns:
oor=
"http://openoffice.org/2001/registry"
40 xmlns:
install=
"http://openoffice.org/2004/installation">
42 <!-- Get the correct format -->
43 <xsl:output method=
"xml" indent=
"yes" />
45 <xsl:param name=
"xcs"/>
46 <xsl:param name=
"schemaRoot">.
</xsl:param>
48 <xsl:variable name=
"schemaRootURL">
49 <xsl:value-of select=
"$schemaRoot"/>
51 <xsl:variable name=
"schemaURL">
52 <xsl:value-of select=
"$xcs"/>
55 <!-- ************************************** -->
56 <!-- * oor:component-data *** -->
57 <!-- ************************************** -->
58 <xsl:template match=
"/oor:component-data">
59 <xsl:variable name=
"component-schema" select=
"document($schemaURL)/oor:component-schema"/>
60 <xsl:for-each select=
"node|prop">
61 <xsl:apply-templates select=
".">
62 <xsl:with-param name=
"context" select=
"$component-schema/component/*[@oor:name = current()/@oor:name]"/>
63 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
64 </xsl:apply-templates>
68 <!-- ****************************************** -->
69 <!-- * handle template references *** -->
70 <!-- ****************************************** -->
71 <xsl:template name=
"resolve-template">
72 <xsl:param name =
"node-type"/>
73 <xsl:param name =
"schema-type"/>
74 <xsl:param name =
"component-schema"/>
75 <xsl:variable name =
"path">
76 <xsl:call-template name=
"collectPath"/>
79 <xsl:if test=
"not ($component-schema)">
80 <xsl:message terminate=
"yes">ERROR: Template '
<xsl:value-of select=
"$node-type"/>',
81 referenced from node '
<xsl:value-of select=
"$path"/>'
82 does not exist in schema!
87 <xsl:when test=
"$schema-type='node-ref'">
88 <xsl:apply-templates select=
".">
89 <xsl:with-param name=
"context" select=
"$component-schema/templates/*[@oor:name = $node-type]"/>
90 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
91 </xsl:apply-templates>
93 <xsl:when test=
"$schema-type='set'">
94 <xsl:for-each select=
"node|prop">
95 <xsl:apply-templates select=
".">
96 <xsl:with-param name=
"context" select=
"$component-schema/templates/*[@oor:name = $node-type]"/>
97 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
98 </xsl:apply-templates>
102 <xsl:message terminate=
"yes">ERROR: The schema element for node
<xsl:value-of select=
"$path"/>
103 is a
<xsl:value-of select=
"$schema-type"/> and should not have a node-type.
109 <!-- ****************************************** -->
111 <!-- ****************************************** -->
112 <xsl:template match=
"node">
113 <xsl:param name =
"context"/>
114 <xsl:param name =
"component-schema"/>
115 <xsl:variable name =
"path">
116 <xsl:call-template name=
"collectPath"/>
119 <xsl:if test=
"not ($context)">
120 <xsl:message terminate=
"yes">ERROR: Node '
<xsl:value-of select=
"$path"/>' does not exist in schema!
</xsl:message>
123 <xsl:call-template name=
"checkModule"/>
124 <xsl:call-template name=
"checkDuplicates"/>
127 <!-- look for matching templates in other components -->
128 <xsl:when test=
"$context/@oor:node-type and $context/@oor:component">
129 <xsl:variable name=
"fileURL">
130 <xsl:call-template name=
"composeFileURL">
131 <xsl:with-param name=
"componentName"><xsl:value-of select=
"$context/@oor:component"/></xsl:with-param>
135 <xsl:call-template name=
"resolve-template">
136 <xsl:with-param name=
"node-type" select=
"$context/@oor:node-type"/>
137 <xsl:with-param name=
"schema-type" select=
"local-name($context)"/>
138 <xsl:with-param name=
"component-schema" select=
"document($fileURL)/oor:component-schema"/>
141 <!-- look for matching templates within the same component -->
142 <xsl:when test=
"$context/@oor:node-type">
143 <xsl:call-template name=
"resolve-template">
144 <xsl:with-param name=
"node-type" select=
"$context/@oor:node-type"/>
145 <xsl:with-param name=
"schema-type" select=
"local-name($context)"/>
146 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
149 <!-- is the node extensible ? -->
150 <xsl:when test=
"$context/@oor:extensible='true'">
151 <xsl:for-each select=
"node|prop">
152 <xsl:apply-templates select=
"." mode=
"extensible">
153 <xsl:with-param name=
"context" select=
"$context/*[@oor:name = current()/@oor:name]"/>
154 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
155 </xsl:apply-templates>
159 <xsl:for-each select=
"node|prop">
160 <xsl:apply-templates select=
".">
161 <xsl:with-param name=
"context" select=
"$context/*[@oor:name = current()/@oor:name]"/>
162 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
163 </xsl:apply-templates>
169 <!-- ****************************************** -->
171 <!-- ****************************************** -->
172 <xsl:template match=
"prop">
173 <xsl:param name =
"context"/>
174 <xsl:variable name =
"path">
175 <xsl:call-template name=
"collectPath"/>
179 <xsl:if test=
"not ($context)">
180 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' does not exist in schema !
</xsl:message>
183 <xsl:if test=
"@oor:op">
184 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' has unexpected operation '
<xsl:value-of select=
"@oor:op"/>' !
</xsl:message>
187 <xsl:call-template name=
"checkModule"/>
188 <xsl:call-template name=
"checkDuplicates"/>
190 <xsl:apply-templates />
193 <!-- ****************************************** -->
195 <!-- ****************************************** -->
196 <xsl:template match=
"value">
197 <xsl:call-template name=
"checkModule"/>
199 <xsl:if test=
"@install:module">
200 <xsl:variable name =
"path">
201 <xsl:call-template name=
"collectPath"/>
203 <xsl:variable name =
"module" select=
"@install:module"/>
204 <xsl:variable name =
"lang" select=
"@xml:lang"/>
206 <xsl:if test=
"following-sibling::value[@install:module=$module and @xml:lang=$lang]">
207 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' has multiple values for module
<xsl:value-of select=
"$module"/> and locale
<xsl:value-of select=
"$lang"/>!
</xsl:message>
209 <xsl:if test=
"../value[not(@install:module)]">
210 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' has values both with and without module. This is currently not supported. Please contact jb@openoffice.org, if you need this!
</xsl:message>
212 <xsl:if test=
"not(preceding-sibling::value/@install:module)">
213 <xsl:message>ATTENTION: Property '
<xsl:value-of select=
"$path"/>' has different values for different modules. Make sure the modules are mutually exclusive!
</xsl:message>
218 <!-- ****************************************** -->
219 <!-- * node (mode:extensible) - not supported * -->
220 <!-- ****************************************** -->
221 <xsl:template match=
"node" mode=
"extensible">
222 <xsl:variable name =
"path">
223 <xsl:call-template name=
"collectPath"/>
226 <xsl:message terminate=
"yes">ERROR: Node '
<xsl:value-of select=
"$path"/>' is within an extensible node!
</xsl:message>
228 <!-- ****************************************** -->
229 <!-- * prop (mode:extensible) *** -->
230 <!-- ****************************************** -->
231 <xsl:template match=
"prop" mode=
"extensible">
232 <xsl:param name =
"context"/>
233 <xsl:variable name =
"path">
234 <xsl:call-template name=
"collectPath"/>
238 <xsl:when test=
"not(@oor:op)">
239 <xsl:if test=
"not ($context)">
240 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' does not exist in schema!
</xsl:message>
243 <xsl:when test=
"@oor:op='replace'">
244 <xsl:if test=
"not (@oor:type)">
245 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' does not have a type!
</xsl:message>
249 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' has unexpected operation '
<xsl:value-of select=
"@oor:op"/>'!
</xsl:message>
253 <xsl:call-template name=
"checkModule"/>
254 <xsl:call-template name=
"checkDuplicates"/>
258 <!-- ************************************* -->
259 <!-- * checkDuplicates *** -->
260 <!-- ************************************* -->
261 <xsl:template name=
"checkDuplicates">
262 <xsl:variable name=
"item-name" select=
"@oor:name"/>
263 <xsl:if test=
"following-sibling::*[@oor:name = $item-name]">
264 <xsl:variable name =
"path">
265 <xsl:call-template name=
"collectPath"/>
267 <xsl:message terminate=
"yes">ERROR: Duplicate node/prop '
<xsl:value-of select=
"$path"/>'!
</xsl:message>
272 <!-- ************************************* -->
273 <!-- * checkModule *** -->
274 <!-- ************************************* -->
275 <xsl:template name=
"checkModule">
276 <xsl:if test=
"@install:module">
277 <xsl:if test=
"ancestor::*[@install:module]">
278 <xsl:message terminate=
"yes">ERROR: Nested modules are not supported. Found module '
<xsl:value-of select=
"@install:module"/>' within module '
<xsl:value-of select=
"ancestor::*/@install:module"/>'!
284 <!-- ************************************* -->
285 <!-- * collectPath *** -->
286 <!-- ************************************* -->
287 <xsl:template name=
"collectPath">
288 <xsl:for-each select=
"ancestor-or-self::node()[@oor:name]">
289 <xsl:text>/
</xsl:text><xsl:value-of select=
"@oor:name"/>
294 <!-- ****************************** -->
295 <!-- * composeFileURL *** -->
296 <!-- ****************************** -->
297 <xsl:template name=
"composeFileURL">
298 <xsl:param name=
"componentName"/>
299 <xsl:variable name=
"fileURL">
300 <xsl:value-of select=
"$schemaRootURL"/>/
<xsl:value-of select=
"translate($componentName,'.','/')"/><xsl:text>.xcs
</xsl:text>
302 <xsl:value-of select=
"$fileURL"/>