1 <?xml version=
"1.0" encoding=
"utf-8" standalone=
"yes" ?>
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 .
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"/>
38 <xsl:variable name=
"schemaURL">
39 <xsl:value-of select=
"$xcs"/>
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>
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"/>
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!
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>
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>
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.
100 <!-- ****************************************** -->
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"/>
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>
115 <xsl:call-template name=
"checkModule"/>
116 <xsl:call-template name=
"checkDuplicates"/>
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>
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"/>
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"/>
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>
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>
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>
167 <!-- ****************************************** -->
169 <!-- ****************************************** -->
170 <xsl:template match=
"prop">
171 <xsl:param name =
"context"/>
172 <xsl:variable name =
"path">
173 <xsl:call-template name=
"collectPath"/>
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>
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>
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>
193 <xsl:call-template name=
"checkModule"/>
194 <xsl:call-template name=
"checkDuplicates"/>
196 <xsl:apply-templates />
199 <!-- ****************************************** -->
201 <!-- ****************************************** -->
202 <xsl:template match=
"value">
203 <xsl:call-template name=
"checkModule"/>
204 <xsl:variable name=
"path">
205 <xsl:call-template name=
"collectPath"/>
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>
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>
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>
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"/>
232 <xsl:message terminate=
"yes">ERROR: Node '
<xsl:value-of select=
"$path"/>' is within an extensible node!
</xsl:message>
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"/>
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>
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>
255 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' has unexpected operation '
<xsl:value-of select=
"@oor:op"/>'!
</xsl:message>
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>
266 <xsl:call-template name=
"checkModule"/>
267 <xsl:call-template name=
"checkDuplicates"/>
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"/>
280 <xsl:message terminate=
"yes">ERROR: Duplicate node/prop '
<xsl:value-of select=
"$path"/>'!
</xsl:message>
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"/>'!
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"/>
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>
315 <xsl:value-of select=
"$fileURL"/>