Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / officecfg / util / data_val.xsl
blob3e2200dbd526c8a88bba630f3f6b69daac8feda0
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:with-param name="parent-schema-type" select="local-name($component-schema)"/>
52 </xsl:apply-templates>
53 </xsl:for-each>
54 </xsl:template>
56 <!-- ****************************************** -->
57 <!-- * handle template references *** -->
58 <!-- ****************************************** -->
59 <xsl:template name="resolve-template">
60 <xsl:param name = "node-type"/>
61 <xsl:param name = "schema-type"/>
62 <xsl:param name = "component-schema"/>
63 <xsl:variable name = "path">
64 <xsl:call-template name="collectPath"/>
65 </xsl:variable>
67 <xsl:if test="not ($component-schema)">
68 <xsl:message terminate="yes">ERROR: Template '<xsl:value-of select="$node-type"/>',
69 referenced from node '<xsl:value-of select="$path"/>'
70 does not exist in schema!
71 </xsl:message>
72 </xsl:if>
74 <xsl:choose>
75 <xsl:when test="$schema-type='node-ref'">
76 <xsl:variable name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
77 <xsl:apply-templates select=".">
78 <xsl:with-param name="context" select="$context"/>
79 <xsl:with-param name="component-schema" select="$component-schema"/>
80 <xsl:with-param name="parent-schema-type" select="local-name($context)"/>
81 </xsl:apply-templates>
82 </xsl:when>
83 <xsl:when test="$schema-type='set'">
84 <xsl:for-each select="node|prop">
85 <xsl:apply-templates select=".">
86 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
87 <xsl:with-param name="component-schema" select="$component-schema"/>
88 <xsl:with-param name="parent-schema-type" select="$schema-type"/>
89 </xsl:apply-templates>
90 </xsl:for-each>
91 </xsl:when>
92 <xsl:otherwise>
93 <xsl:message terminate="yes">ERROR: The schema element for node <xsl:value-of select="$path"/>
94 is a <xsl:value-of select="$schema-type"/> and should not have a node-type.
95 </xsl:message>
96 </xsl:otherwise>
97 </xsl:choose>
98 </xsl:template>
100 <!-- ****************************************** -->
101 <!-- * node *** -->
102 <!-- ****************************************** -->
103 <xsl:template match="node">
104 <xsl:param name = "context"/>
105 <xsl:param name = "component-schema"/>
106 <xsl:param name = "parent-schema-type"/>
107 <xsl:variable name = "path">
108 <xsl:call-template name="collectPath"/>
109 </xsl:variable>
111 <xsl:if test="not ($context)">
112 <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message>
113 </xsl:if>
115 <xsl:call-template name="checkModule"/>
116 <xsl:call-template name="checkDuplicates"/>
118 <xsl:choose>
119 <!-- look for matching templates in other components -->
120 <xsl:when test="$context/@oor:node-type and $context/@oor:component">
121 <xsl:variable name="fileURL">
122 <xsl:call-template name="composeFileURL">
123 <xsl:with-param name="componentName"><xsl:value-of select="$context/@oor:component"/></xsl:with-param>
124 </xsl:call-template>
125 </xsl:variable>
127 <xsl:call-template name="resolve-template">
128 <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
129 <xsl:with-param name="schema-type" select="local-name($context)"/>
130 <xsl:with-param name="component-schema" select="document($fileURL)/oor:component-schema"/>
131 </xsl:call-template>
132 </xsl:when>
133 <!-- look for matching templates within the same component -->
134 <xsl:when test="$context/@oor:node-type">
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="$component-schema"/>
139 </xsl:call-template>
140 </xsl:when>
141 <!-- is the node extensible ? -->
142 <xsl:when test="$context/@oor:extensible='true'">
143 <xsl:for-each select="node|prop">
144 <xsl:apply-templates select="." mode="extensible">
145 <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/>
146 <xsl:with-param name="component-schema" select="$component-schema"/>
147 <xsl:with-param name="parent-schema-type" select="local-name($context)"/>
148 </xsl:apply-templates>
149 </xsl:for-each>
150 </xsl:when>
151 <xsl:otherwise>
152 <xsl:for-each select="node|prop">
153 <xsl:apply-templates select=".">
154 <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/>
155 <xsl:with-param name="component-schema" select="$component-schema"/>
156 <xsl:with-param name="parent-schema-type" select="local-name($context)"/>
157 </xsl:apply-templates>
158 </xsl:for-each>
159 </xsl:otherwise>
160 </xsl:choose>
162 <xsl:if test="@oor:mandatory='true' and $parent-schema-type!='set'">
163 <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' that is not a set element is marked as mandatory!</xsl:message>
164 </xsl:if>
165 </xsl:template>
167 <!-- ****************************************** -->
168 <!-- * prop *** -->
169 <!-- ****************************************** -->
170 <xsl:template match="prop">
171 <xsl:param name = "context"/>
172 <xsl:variable name = "path">
173 <xsl:call-template name="collectPath"/>
174 </xsl:variable>
177 <xsl:if test="not ($context)">
178 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema !</xsl:message>
179 </xsl:if>
181 <xsl:if test="@oor:op">
182 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>' !</xsl:message>
183 </xsl:if>
185 <xsl:if test="not($context/@oor:localized='true')">
186 <xsl:for-each select="value">
187 <xsl:if test="@xml:lang">
188 <xsl:message terminate="yes">ERROR: Non-localized property '<xsl:value-of select="$path"/>' has value for xml:lang='<xsl:value-of select="@xml:lang"/>'!</xsl:message>
189 </xsl:if>
190 </xsl:for-each>
191 </xsl:if>
193 <xsl:call-template name="checkModule"/>
194 <xsl:call-template name="checkDuplicates"/>
196 <xsl:apply-templates />
197 </xsl:template>
199 <!-- ****************************************** -->
200 <!-- * value *** -->
201 <!-- ****************************************** -->
202 <xsl:template match="value">
203 <xsl:call-template name="checkModule"/>
204 <xsl:variable name="path">
205 <xsl:call-template name="collectPath"/>
206 </xsl:variable>
207 <xsl:variable name="lang" select="@xml:lang"/>
208 <xsl:variable name="module" select="@install:module"/>
209 <xsl:if test="$module and $lang='x-no-translate'">
210 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has value for special xml:lang="x-no-translate" in module <xsl:value-of select="$module"/>.</xsl:message>
211 </xsl:if>
212 <xsl:choose>
213 <xsl:when
214 test="preceding-sibling::value[($lang and not(@xml:lang)) or (not($lang) and @xml:lang)]">
215 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has values with and without xml:lang attributes.</xsl:message>
216 </xsl:when>
217 <xsl:when
218 test="preceding-sibling::value[((not($lang) and not(@xml:lang)) or $lang=@xml:lang) and ((not($module) and not(@install:module)) or $module=@install:module)]">
219 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has values with matching xml:lang attribute <xsl:value-of select="$lang"/> and inconsistent install:module attributes.</xsl:message>
220 </xsl:when>
221 </xsl:choose>
222 </xsl:template>
224 <!-- ****************************************** -->
225 <!-- * node (mode:extensible) - not supported * -->
226 <!-- ****************************************** -->
227 <xsl:template match="node" mode="extensible">
228 <xsl:variable name = "path">
229 <xsl:call-template name="collectPath"/>
230 </xsl:variable>
232 <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' is within an extensible node!</xsl:message>
233 </xsl:template>
234 <!-- ****************************************** -->
235 <!-- * prop (mode:extensible) *** -->
236 <!-- ****************************************** -->
237 <xsl:template match="prop" mode="extensible">
238 <xsl:param name = "context"/>
239 <xsl:variable name = "path">
240 <xsl:call-template name="collectPath"/>
241 </xsl:variable>
243 <xsl:choose>
244 <xsl:when test="not(@oor:op)">
245 <xsl:if test="not ($context)">
246 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message>
247 </xsl:if>
248 </xsl:when>
249 <xsl:when test="@oor:op='replace'">
250 <xsl:if test="not (@oor:type)">
251 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not have a type!</xsl:message>
252 </xsl:if>
253 </xsl:when>
254 <xsl:otherwise>
255 <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>'!</xsl:message>
256 </xsl:otherwise>
257 </xsl:choose>
259 <!-- Extension properties are always non-localized: -->
260 <xsl:for-each select="value">
261 <xsl:if test="@xml:lang">
262 <xsl:message terminate="yes">ERROR: Non-localized extension property '<xsl:value-of select="$path"/>' has value for xml:lang='<xsl:value-of select="@xml:lang"/>'!</xsl:message>
263 </xsl:if>
264 </xsl:for-each>
266 <xsl:call-template name="checkModule"/>
267 <xsl:call-template name="checkDuplicates"/>
268 </xsl:template>
271 <!-- ************************************* -->
272 <!-- * checkDuplicates *** -->
273 <!-- ************************************* -->
274 <xsl:template name="checkDuplicates">
275 <xsl:variable name="item-name" select="@oor:name"/>
276 <xsl:if test="following-sibling::*[@oor:name = $item-name]">
277 <xsl:variable name = "path">
278 <xsl:call-template name="collectPath"/>
279 </xsl:variable>
280 <xsl:message terminate="yes">ERROR: Duplicate node/prop '<xsl:value-of select="$path"/>'!</xsl:message>
281 </xsl:if>
282 </xsl:template>
285 <!-- ************************************* -->
286 <!-- * checkModule *** -->
287 <!-- ************************************* -->
288 <xsl:template name="checkModule">
289 <xsl:if test="@install:module">
290 <xsl:if test="ancestor::*[@install:module]">
291 <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"/>'!
292 </xsl:message>
293 </xsl:if>
294 </xsl:if>
295 </xsl:template>
297 <!-- ************************************* -->
298 <!-- * collectPath *** -->
299 <!-- ************************************* -->
300 <xsl:template name="collectPath">
301 <xsl:for-each select="ancestor-or-self::node()[@oor:name]">
302 <xsl:text>/</xsl:text><xsl:value-of select="@oor:name"/>
303 </xsl:for-each>
304 </xsl:template>
307 <!-- ****************************** -->
308 <!-- * composeFileURL *** -->
309 <!-- ****************************** -->
310 <xsl:template name="composeFileURL">
311 <xsl:param name="componentName"/>
312 <xsl:variable name="fileURL">
313 <xsl:value-of select="$schemaRootURL"/>/<xsl:value-of select="translate($componentName,'.','/')"/><xsl:text>.xcs</xsl:text>
314 </xsl:variable>
315 <xsl:value-of select="$fileURL"/>
316 </xsl:template>
319 </xsl:transform>