update dev300-m58
[ooovba.git] / officecfg / util / data_val.xsl
blobbdf7c1ba2546824990e575866b7574d5e1e54021
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 $
12 $Revision: 1.10 $
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"/>
50 </xsl:variable>
51 <xsl:variable name="schemaURL">
52 <xsl:value-of select="$xcs"/>
53 </xsl:variable>
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>
65 </xsl:for-each>
66 </xsl:template>
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"/>
77 </xsl:variable>
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!
83 </xsl:message>
84 </xsl:if>
86 <xsl:choose>
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>
92 </xsl:when>
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>
99 </xsl:for-each>
100 </xsl:when>
101 <xsl:otherwise>
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.
104 </xsl:message>
105 </xsl:otherwise>
106 </xsl:choose>
107 </xsl:template>
109 <!-- ****************************************** -->
110 <!-- * node *** -->
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"/>
117 </xsl:variable>
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>
121 </xsl:if>
123 <xsl:call-template name="checkModule"/>
124 <xsl:call-template name="checkDuplicates"/>
126 <xsl:choose>
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>
132 </xsl:call-template>
133 </xsl:variable>
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"/>
139 </xsl:call-template>
140 </xsl:when>
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"/>
147 </xsl:call-template>
148 </xsl:when>
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>
156 </xsl:for-each>
157 </xsl:when>
158 <xsl:otherwise>
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>
164 </xsl:for-each>
165 </xsl:otherwise>
166 </xsl:choose>
167 </xsl:template>
169 <!-- ****************************************** -->
170 <!-- * prop *** -->
171 <!-- ****************************************** -->
172 <xsl:template match="prop">
173 <xsl:param name = "context"/>
174 <xsl:variable name = "path">
175 <xsl:call-template name="collectPath"/>
176 </xsl:variable>
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>
181 </xsl:if>
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>
185 </xsl:if>
187 <xsl:call-template name="checkModule"/>
188 <xsl:call-template name="checkDuplicates"/>
190 <xsl:apply-templates />
191 </xsl:template>
193 <!-- ****************************************** -->
194 <!-- * value *** -->
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"/>
202 </xsl:variable>
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>
208 </xsl:if>
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>
211 </xsl:if>
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>
214 </xsl:if>
215 </xsl:if>
216 </xsl:template>
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"/>
224 </xsl:variable>
226 <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' is within an extensible node!</xsl:message>
227 </xsl:template>
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"/>
235 </xsl:variable>
237 <xsl:choose>
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>
241 </xsl:if>
242 </xsl:when>
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>
246 </xsl:if>
247 </xsl:when>
248 <xsl:otherwise>
249 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>'!</xsl:message>
250 </xsl:otherwise>
251 </xsl:choose>
253 <xsl:call-template name="checkModule"/>
254 <xsl:call-template name="checkDuplicates"/>
255 </xsl:template>
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"/>
266 </xsl:variable>
267 <xsl:message terminate="yes">ERROR: Duplicate node/prop '<xsl:value-of select="$path"/>'!</xsl:message>
268 </xsl:if>
269 </xsl:template>
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"/>'!
279 </xsl:message>
280 </xsl:if>
281 </xsl:if>
282 </xsl:template>
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"/>
290 </xsl:for-each>
291 </xsl:template>
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>
301 </xsl:variable>
302 <xsl:value-of select="$fileURL"/>
303 </xsl:template>
306 </xsl:transform>