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 <xsl:transform xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform" version=
"1.0"
21 xmlns:
xsi=
"http://www.w3.org/2001/XMLSchema-instance"
22 xmlns:
xs=
"http://www.w3.org/2001/XMLSchema"
23 xmlns:
oor=
"http://openoffice.org/2001/registry"
24 xmlns:
install=
"http://openoffice.org/2004/installation"
25 exclude-result-prefixes=
"install">
27 <!-- Get the correct format -->
28 <xsl:output method=
"xml" indent=
"yes" encoding=
"UTF-8"/>
30 <!--************************** PARAMETER ******************************** -->
31 <xsl:param name=
"locale"/>
32 <xsl:param name=
"module"/>
33 <xsl:param name=
"xcs"/>
34 <xsl:param name=
"schemaRoot">.
</xsl:param>
35 <xsl:param name=
"fallback-locale">en-US
</xsl:param>
37 <xsl:variable name=
"schemaRootURL">
38 <xsl:value-of select=
"$schemaRoot"/>
40 <xsl:variable name=
"schemaURL">
41 <xsl:value-of select=
"$xcs"/>
44 <!--************************** TEMPLATES ******************************** -->
45 <!-- ensure that at least root is available -->
46 <xsl:template match=
"/oor:component-data">
49 <xsl:when test=
"string-length($locale)">
50 <xsl:apply-templates select =
"@*" mode=
"locale"/>
51 <xsl:apply-templates select =
"node|prop" mode=
"locale"/>
54 <xsl:apply-templates select =
"@*"/>
55 <xsl:for-each select=
"node|prop">
56 <xsl:variable name=
"component-schema" select=
"document($schemaURL)/oor:component-schema"/>
57 <xsl:apply-templates select=
".">
58 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
59 <xsl:with-param name=
"context" select=
"$component-schema/component/*[@oor:name = current()/@oor:name]"/>
60 <xsl:with-param name=
"find-module" select=
"$module"/>
61 </xsl:apply-templates>
68 <!-- locale dependent data -->
69 <xsl:template match=
"node|prop" mode =
"locale">
71 <xsl:when test=
"$locale=$fallback-locale">
72 <xsl:if test=
"descendant::value[@xml:lang=$locale]/../value[not (@xml:lang)]">
74 <xsl:apply-templates select =
"@*" mode=
"locale"/>
75 <xsl:apply-templates select =
"node|prop|value" mode =
"locale"/>
80 <xsl:if test=
"descendant::value[@xml:lang = $locale]">
82 <xsl:apply-templates select =
"@*" mode=
"locale"/>
83 <xsl:apply-templates select =
"node|prop|value" mode =
"locale"/>
90 <xsl:template match=
"value" mode=
"locale">
91 <xsl:if test=
"@xml:lang=$locale and not(@install:module)">
93 <xsl:apply-templates select =
"@*" mode=
"locale"/>
94 <xsl:copy-of select=
"node()"/>
99 <xsl:template match =
"@*" mode=
"locale">
103 <!-- suppress all merge instructions -->
104 <xsl:template match =
"@oor:op" mode=
"locale"/>
106 <!-- suppress all module markers -->
107 <xsl:template match =
"@install:module" mode=
"locale"/>
109 <!-- locale independent data -->
111 <!-- handle template references -->
112 <xsl:template name=
"copy-resolve-template">
113 <xsl:param name =
"node-type"/>
114 <xsl:param name =
"schema-type"/>
115 <xsl:param name =
"component-schema"/>
118 <xsl:when test=
"$schema-type='node-ref'">
119 <xsl:apply-templates select=
".">
120 <xsl:with-param name=
"context" select=
"$component-schema/templates/*[@oor:name = $node-type]"/>
121 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
122 </xsl:apply-templates>
124 <xsl:when test=
"$schema-type='set'">
126 <xsl:apply-templates select =
"@*" />
127 <xsl:for-each select=
"node|prop">
128 <xsl:apply-templates select=
".">
129 <xsl:with-param name=
"context" select=
"$component-schema/templates/*[@oor:name = $node-type]"/>
130 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
131 </xsl:apply-templates>
136 <xsl:message terminate=
"yes">ERROR: The schema element for a
<xsl:value-of select=
"$schema-type"/>
137 should not have a node-type.
143 <xsl:template name=
"copy-node">
144 <xsl:param name =
"context"/>
145 <xsl:param name =
"component-schema"/>
148 <!-- look for matching templates in other components -->
149 <xsl:when test=
"$context/@oor:node-type and $context/@oor:component">
150 <xsl:variable name=
"fileURL">
151 <xsl:call-template name=
"composeFileURL">
152 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
153 <xsl:with-param name=
"componentName"><xsl:value-of select=
"$context/@oor:component"/></xsl:with-param>
156 <xsl:call-template name=
"copy-resolve-template">
157 <xsl:with-param name=
"node-type" select=
"$context/@oor:node-type"/>
158 <xsl:with-param name=
"schema-type" select=
"local-name($context)"/>
159 <xsl:with-param name=
"component-schema" select=
"document($fileURL)/oor:component-schema"/>
162 <!-- look for matching templates within the same component -->
163 <xsl:when test=
"$context/@oor:node-type">
164 <xsl:call-template name=
"copy-resolve-template">
165 <xsl:with-param name=
"node-type" select=
"$context/@oor:node-type"/>
166 <xsl:with-param name=
"schema-type" select=
"local-name($context)"/>
167 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
172 <xsl:apply-templates select =
"@*" />
173 <xsl:for-each select=
"node|prop">
174 <xsl:apply-templates select=
".">
175 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
176 <xsl:with-param name=
"context" select=
"$context/*[@oor:name = current()/@oor:name]"/>
177 </xsl:apply-templates>
184 <xsl:template match=
"node">
185 <xsl:param name =
"context"/>
186 <xsl:param name =
"component-schema"/>
188 <xsl:variable name=
"applicable-values" select=
"descendant::value[not (@xml:lang) or (@xml:lang=$fallback-locale) or (@install:module=$module)]"/>
189 <xsl:variable name=
"substantive-nodes" select=
"descendant-or-self::*[(@oor:finalized='true') or (@oor:mandatory='true') or (@oor:op!='modify')]"/>
192 <!-- go ahead, if we are in the active module -->
193 <xsl:when test=
"ancestor-or-self::*/@install:module=$module">
194 <xsl:if test=
"$applicable-values | $substantive-nodes">
195 <xsl:call-template name=
"copy-node">
196 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
197 <xsl:with-param name=
"context" select=
"$context"/>
201 <!-- strip data from wrong module -->
202 <xsl:when test=
"ancestor-or-self::*/@install:module"/>
203 <!-- looking for module -->
204 <xsl:when test=
"$module">
205 <xsl:if test=
"($applicable-values | $substantive-nodes)/ancestor-or-self::*/@install:module=$module">
206 <xsl:call-template name=
"copy-node">
207 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
208 <xsl:with-param name=
"context" select=
"$context"/>
212 <!-- copying non-module data -->
214 <xsl:if test=
"($applicable-values | $substantive-nodes)[not(ancestor-or-self::*/@install:module)]">
215 <xsl:call-template name=
"copy-node">
216 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
217 <xsl:with-param name=
"context" select=
"$context"/>
224 <xsl:template match=
"prop">
225 <xsl:param name =
"context"/>
227 <xsl:when test=
"$module and not((ancestor-or-self::* | child::value)/@install:module=$module)"/>
228 <xsl:when test=
"not($module) and ancestor-or-self::*/@install:module"/>
229 <xsl:when test=
"not ($context) or @oor:finalized='true' or @oor:op!='modify'">
231 <xsl:apply-templates select =
"@*"/>
232 <xsl:apply-templates select =
"value"/>
235 <xsl:when test=
"value[not (@xml:lang) or @install:module]">
236 <xsl:if test=
"value[not(@install:module) or @install:module=$module]">
237 <!-- copy locale independent values only, if the values differ -->
238 <xsl:variable name=
"isRedundant">
239 <xsl:call-template name=
"isRedundant">
240 <xsl:with-param name=
"schemaval" select=
"$context/value"/>
241 <xsl:with-param name=
"dataval" select=
"value[(not(@xml:lang) or @install:module) and (not(@install:module) or @install:module=$module)]"/>
244 <xsl:if test=
"$isRedundant ='false'">
246 <xsl:apply-templates select =
"@*"/>
247 <xsl:apply-templates select =
"value"/>
254 <xsl:apply-templates select =
"@*"/>
255 <xsl:apply-templates select =
"value" mode=
"fallback-locale"/>
261 <xsl:template match=
"value">
263 <xsl:when test=
"@xml:lang and not(@install:module)"/>
264 <xsl:when test=
"$module and not(ancestor-or-self::*/@install:module=$module)"/>
265 <xsl:when test=
"not($module) and ancestor-or-self::*/@install:module"/>
268 <xsl:apply-templates select =
"@*"/>
269 <xsl:copy-of select=
"node()"/>
275 <xsl:template match=
"value" mode=
"fallback-locale">
276 <xsl:if test=
"@xml:lang=$fallback-locale and not(@install:module)">
278 <xsl:apply-templates select =
"@*"/>
279 <xsl:copy-of select=
"node()"/>
284 <xsl:template match =
"@*">
288 <!-- suppress all merge instructions, that are out-of-module -->
289 <xsl:template match =
"@oor:op">
290 <xsl:if test=
"not($module) or ancestor::*/@install:module">
295 <!-- suppress all module markers -->
296 <xsl:template match =
"@install:module"/>
298 <!-- compares two values -->
299 <xsl:template name=
"isRedundant">
300 <xsl:param name =
"schemaval"/>
301 <xsl:param name =
"dataval"/>
303 <xsl:when test=
"not ($dataval)">
304 <xsl:value-of select=
"true()"/>
306 <xsl:when test=
"$dataval/@oor:external">
307 <xsl:value-of select=
"false()"/>
309 <xsl:when test=
"not ($schemaval)">
311 <xsl:when test=
"$dataval/@xsi:nil='true'">
312 <xsl:value-of select=
"true()"/>
315 <xsl:value-of select=
"false()"/>
319 <xsl:when test=
"$schemaval != $dataval">
320 <xsl:value-of select=
"false()"/>
323 <xsl:value-of select=
"true()"/>
328 <xsl:template name=
"composeFileURL">
329 <xsl:param name=
"componentName"/>
330 <xsl:variable name=
"fileURL">
331 <xsl:value-of select=
"$schemaRootURL"/>/
<xsl:value-of select=
"translate($componentName,'.','/')"/><xsl:text>.xcs
</xsl:text>
333 <xsl:value-of select=
"$fileURL"/>