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:apply-templates>
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"/>
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!
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>
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>
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.
96 <!-- ****************************************** -->
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"/>
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>
110 <xsl:call-template name=
"checkModule"/>
111 <xsl:call-template name=
"checkDuplicates"/>
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>
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"/>
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"/>
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>
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>
156 <!-- ****************************************** -->
158 <!-- ****************************************** -->
159 <xsl:template match=
"prop">
160 <xsl:param name =
"context"/>
161 <xsl:variable name =
"path">
162 <xsl:call-template name=
"collectPath"/>
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>
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>
174 <xsl:call-template name=
"checkModule"/>
175 <xsl:call-template name=
"checkDuplicates"/>
177 <xsl:apply-templates />
180 <!-- ****************************************** -->
182 <!-- ****************************************** -->
183 <xsl:template match=
"value">
184 <xsl:call-template name=
"checkModule"/>
185 <xsl:variable name=
"path">
186 <xsl:call-template name=
"collectPath"/>
188 <xsl:variable name=
"lang" select=
"@xml:lang"/>
189 <xsl:variable name=
"module" select=
"@install:module"/>
190 <xsl:if test=
"$module and $lang='x-no-translate'">
191 <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>
195 test=
"preceding-sibling::value[($lang and not(@xml:lang)) or (not($lang) and @xml:lang)]">
196 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' has values with and without xml:lang attributes.
</xsl:message>
199 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)]">
200 <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>
203 test=
"preceding-sibling::value[((not($lang) and not(@xml:lang)) or $lang=@xml:lang) and (($module and not(@install:module)) or (not($module) and @install:module) or $module!=@install:module)]">
204 <xsl:message>ATTENTION: Property '
<xsl:value-of select=
"$path"/>' has different values for different modules. Make sure the modules are mutually exclusive!
</xsl:message>
209 <!-- ****************************************** -->
210 <!-- * node (mode:extensible) - not supported * -->
211 <!-- ****************************************** -->
212 <xsl:template match=
"node" mode=
"extensible">
213 <xsl:variable name =
"path">
214 <xsl:call-template name=
"collectPath"/>
217 <xsl:message terminate=
"yes">ERROR: Node '
<xsl:value-of select=
"$path"/>' is within an extensible node!
</xsl:message>
219 <!-- ****************************************** -->
220 <!-- * prop (mode:extensible) *** -->
221 <!-- ****************************************** -->
222 <xsl:template match=
"prop" mode=
"extensible">
223 <xsl:param name =
"context"/>
224 <xsl:variable name =
"path">
225 <xsl:call-template name=
"collectPath"/>
229 <xsl:when test=
"not(@oor:op)">
230 <xsl:if test=
"not ($context)">
231 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' does not exist in schema!
</xsl:message>
234 <xsl:when test=
"@oor:op='replace'">
235 <xsl:if test=
"not (@oor:type)">
236 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' does not have a type!
</xsl:message>
240 <xsl:message terminate=
"yes">ERROR: Property '
<xsl:value-of select=
"$path"/>' has unexpected operation '
<xsl:value-of select=
"@oor:op"/>'!
</xsl:message>
244 <xsl:call-template name=
"checkModule"/>
245 <xsl:call-template name=
"checkDuplicates"/>
249 <!-- ************************************* -->
250 <!-- * checkDuplicates *** -->
251 <!-- ************************************* -->
252 <xsl:template name=
"checkDuplicates">
253 <xsl:variable name=
"item-name" select=
"@oor:name"/>
254 <xsl:if test=
"following-sibling::*[@oor:name = $item-name]">
255 <xsl:variable name =
"path">
256 <xsl:call-template name=
"collectPath"/>
258 <xsl:message terminate=
"yes">ERROR: Duplicate node/prop '
<xsl:value-of select=
"$path"/>'!
</xsl:message>
263 <!-- ************************************* -->
264 <!-- * checkModule *** -->
265 <!-- ************************************* -->
266 <xsl:template name=
"checkModule">
267 <xsl:if test=
"@install:module">
268 <xsl:if test=
"ancestor::*[@install:module]">
269 <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"/>'!
275 <!-- ************************************* -->
276 <!-- * collectPath *** -->
277 <!-- ************************************* -->
278 <xsl:template name=
"collectPath">
279 <xsl:for-each select=
"ancestor-or-self::node()[@oor:name]">
280 <xsl:text>/
</xsl:text><xsl:value-of select=
"@oor:name"/>
285 <!-- ****************************** -->
286 <!-- * composeFileURL *** -->
287 <!-- ****************************** -->
288 <xsl:template name=
"composeFileURL">
289 <xsl:param name=
"componentName"/>
290 <xsl:variable name=
"fileURL">
291 <xsl:value-of select=
"$schemaRootURL"/>/
<xsl:value-of select=
"translate($componentName,'.','/')"/><xsl:text>.xcs
</xsl:text>
293 <xsl:value-of select=
"$fileURL"/>