bump product version to 4.1.6.2
[LibreOffice.git] / officecfg / util / data_val.xsl
blobfcd7a16a7162ee6897feb30434b03e1c13a5e5e4
1 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2 <!--
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 -->
20 <!-- ************************************************************************************** -->
21 <!-- * Transformation from New Format XCS & XCU to schema description *** -->
22 <!-- ************************************************************************************** -->
23 <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
24 xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
25 xmlns:xs="http://www.w3.org/2001/XMLSchema"
26 xmlns:oor="http://openoffice.org/2001/registry"
27 xmlns:install="http://openoffice.org/2004/installation">
29 <!-- Get the correct format -->
30 <xsl:output method="xml" indent="yes" />
32 <xsl:param name="xcs"/>
33 <xsl:param name="schemaRoot">.</xsl:param>
35 <xsl:variable name="schemaRootURL">
36 <xsl:value-of select="$schemaRoot"/>
37 </xsl:variable>
38 <xsl:variable name="schemaURL">
39 <xsl:value-of select="$xcs"/>
40 </xsl:variable>
42 <!-- ************************************** -->
43 <!-- * oor:component-data *** -->
44 <!-- ************************************** -->
45 <xsl:template match="/oor:component-data">
46 <xsl:variable name="component-schema" select="document($schemaURL)/oor:component-schema"/>
47 <xsl:for-each select="node|prop">
48 <xsl:apply-templates select=".">
49 <xsl:with-param name="context" select="$component-schema/component/*[@oor:name = current()/@oor:name]"/>
50 <xsl:with-param name="component-schema" select="$component-schema"/>
51 </xsl:apply-templates>
52 </xsl:for-each>
53 </xsl:template>
55 <!-- ****************************************** -->
56 <!-- * handle template references *** -->
57 <!-- ****************************************** -->
58 <xsl:template name="resolve-template">
59 <xsl:param name = "node-type"/>
60 <xsl:param name = "schema-type"/>
61 <xsl:param name = "component-schema"/>
62 <xsl:variable name = "path">
63 <xsl:call-template name="collectPath"/>
64 </xsl:variable>
66 <xsl:if test="not ($component-schema)">
67 <xsl:message terminate="yes">ERROR: Template '<xsl:value-of select="$node-type"/>',
68 referenced from node '<xsl:value-of select="$path"/>'
69 does not exist in schema!
70 </xsl:message>
71 </xsl:if>
73 <xsl:choose>
74 <xsl:when test="$schema-type='node-ref'">
75 <xsl:apply-templates select=".">
76 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
77 <xsl:with-param name="component-schema" select="$component-schema"/>
78 </xsl:apply-templates>
79 </xsl:when>
80 <xsl:when test="$schema-type='set'">
81 <xsl:for-each select="node|prop">
82 <xsl:apply-templates select=".">
83 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
84 <xsl:with-param name="component-schema" select="$component-schema"/>
85 </xsl:apply-templates>
86 </xsl:for-each>
87 </xsl:when>
88 <xsl:otherwise>
89 <xsl:message terminate="yes">ERROR: The schema element for node <xsl:value-of select="$path"/>
90 is a <xsl:value-of select="$schema-type"/> and should not have a node-type.
91 </xsl:message>
92 </xsl:otherwise>
93 </xsl:choose>
94 </xsl:template>
96 <!-- ****************************************** -->
97 <!-- * node *** -->
98 <!-- ****************************************** -->
99 <xsl:template match="node">
100 <xsl:param name = "context"/>
101 <xsl:param name = "component-schema"/>
102 <xsl:variable name = "path">
103 <xsl:call-template name="collectPath"/>
104 </xsl:variable>
106 <xsl:if test="not ($context)">
107 <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message>
108 </xsl:if>
110 <xsl:call-template name="checkModule"/>
111 <xsl:call-template name="checkDuplicates"/>
113 <xsl:choose>
114 <!-- look for matching templates in other components -->
115 <xsl:when test="$context/@oor:node-type and $context/@oor:component">
116 <xsl:variable name="fileURL">
117 <xsl:call-template name="composeFileURL">
118 <xsl:with-param name="componentName"><xsl:value-of select="$context/@oor:component"/></xsl:with-param>
119 </xsl:call-template>
120 </xsl:variable>
122 <xsl:call-template name="resolve-template">
123 <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
124 <xsl:with-param name="schema-type" select="local-name($context)"/>
125 <xsl:with-param name="component-schema" select="document($fileURL)/oor:component-schema"/>
126 </xsl:call-template>
127 </xsl:when>
128 <!-- look for matching templates within the same component -->
129 <xsl:when test="$context/@oor:node-type">
130 <xsl:call-template name="resolve-template">
131 <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
132 <xsl:with-param name="schema-type" select="local-name($context)"/>
133 <xsl:with-param name="component-schema" select="$component-schema"/>
134 </xsl:call-template>
135 </xsl:when>
136 <!-- is the node extensible ? -->
137 <xsl:when test="$context/@oor:extensible='true'">
138 <xsl:for-each select="node|prop">
139 <xsl:apply-templates select="." mode="extensible">
140 <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/>
141 <xsl:with-param name="component-schema" select="$component-schema"/>
142 </xsl:apply-templates>
143 </xsl:for-each>
144 </xsl:when>
145 <xsl:otherwise>
146 <xsl:for-each select="node|prop">
147 <xsl:apply-templates select=".">
148 <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/>
149 <xsl:with-param name="component-schema" select="$component-schema"/>
150 </xsl:apply-templates>
151 </xsl:for-each>
152 </xsl:otherwise>
153 </xsl:choose>
154 </xsl:template>
156 <!-- ****************************************** -->
157 <!-- * prop *** -->
158 <!-- ****************************************** -->
159 <xsl:template match="prop">
160 <xsl:param name = "context"/>
161 <xsl:variable name = "path">
162 <xsl:call-template name="collectPath"/>
163 </xsl:variable>
166 <xsl:if test="not ($context)">
167 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema !</xsl:message>
168 </xsl:if>
170 <xsl:if test="@oor:op">
171 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>' !</xsl:message>
172 </xsl:if>
174 <xsl:call-template name="checkModule"/>
175 <xsl:call-template name="checkDuplicates"/>
177 <xsl:apply-templates />
178 </xsl:template>
180 <!-- ****************************************** -->
181 <!-- * value *** -->
182 <!-- ****************************************** -->
183 <xsl:template match="value">
184 <xsl:call-template name="checkModule"/>
186 <xsl:if test="@install:module">
187 <xsl:variable name = "path">
188 <xsl:call-template name="collectPath"/>
189 </xsl:variable>
190 <xsl:variable name = "module" select="@install:module"/>
191 <xsl:variable name = "lang" select="@xml:lang"/>
193 <xsl:if test="following-sibling::value[@install:module=$module and @xml:lang=$lang]">
194 <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>
195 </xsl:if>
196 <xsl:if test="not(preceding-sibling::value/@install:module)">
197 <xsl:message>ATTENTION: Property '<xsl:value-of select="$path"/>' has different values for different modules. Make sure the modules are mutually exclusive!</xsl:message>
198 </xsl:if>
199 </xsl:if>
200 </xsl:template>
202 <!-- ****************************************** -->
203 <!-- * node (mode:extensible) - not supported * -->
204 <!-- ****************************************** -->
205 <xsl:template match="node" mode="extensible">
206 <xsl:variable name = "path">
207 <xsl:call-template name="collectPath"/>
208 </xsl:variable>
210 <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' is within an extensible node!</xsl:message>
211 </xsl:template>
212 <!-- ****************************************** -->
213 <!-- * prop (mode:extensible) *** -->
214 <!-- ****************************************** -->
215 <xsl:template match="prop" mode="extensible">
216 <xsl:param name = "context"/>
217 <xsl:variable name = "path">
218 <xsl:call-template name="collectPath"/>
219 </xsl:variable>
221 <xsl:choose>
222 <xsl:when test="not(@oor:op)">
223 <xsl:if test="not ($context)">
224 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message>
225 </xsl:if>
226 </xsl:when>
227 <xsl:when test="@oor:op='replace'">
228 <xsl:if test="not (@oor:type)">
229 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not have a type!</xsl:message>
230 </xsl:if>
231 </xsl:when>
232 <xsl:otherwise>
233 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>'!</xsl:message>
234 </xsl:otherwise>
235 </xsl:choose>
237 <xsl:call-template name="checkModule"/>
238 <xsl:call-template name="checkDuplicates"/>
239 </xsl:template>
242 <!-- ************************************* -->
243 <!-- * checkDuplicates *** -->
244 <!-- ************************************* -->
245 <xsl:template name="checkDuplicates">
246 <xsl:variable name="item-name" select="@oor:name"/>
247 <xsl:if test="following-sibling::*[@oor:name = $item-name]">
248 <xsl:variable name = "path">
249 <xsl:call-template name="collectPath"/>
250 </xsl:variable>
251 <xsl:message terminate="yes">ERROR: Duplicate node/prop '<xsl:value-of select="$path"/>'!</xsl:message>
252 </xsl:if>
253 </xsl:template>
256 <!-- ************************************* -->
257 <!-- * checkModule *** -->
258 <!-- ************************************* -->
259 <xsl:template name="checkModule">
260 <xsl:if test="@install:module">
261 <xsl:if test="ancestor::*[@install:module]">
262 <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"/>'!
263 </xsl:message>
264 </xsl:if>
265 </xsl:if>
266 </xsl:template>
268 <!-- ************************************* -->
269 <!-- * collectPath *** -->
270 <!-- ************************************* -->
271 <xsl:template name="collectPath">
272 <xsl:for-each select="ancestor-or-self::node()[@oor:name]">
273 <xsl:text>/</xsl:text><xsl:value-of select="@oor:name"/>
274 </xsl:for-each>
275 </xsl:template>
278 <!-- ****************************** -->
279 <!-- * composeFileURL *** -->
280 <!-- ****************************** -->
281 <xsl:template name="composeFileURL">
282 <xsl:param name="componentName"/>
283 <xsl:variable name="fileURL">
284 <xsl:value-of select="$schemaRootURL"/>/<xsl:value-of select="translate($componentName,'.','/')"/><xsl:text>.xcs</xsl:text>
285 </xsl:variable>
286 <xsl:value-of select="$fileURL"/>
287 </xsl:template>
290 </xsl:transform>