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:param name=
"LIBO_SHARE_FOLDER"/>
38 <xsl:param name=
"LIBO_SHARE_HELP_FOLDER"/>
40 <xsl:variable name=
"schemaRootURL">
41 <xsl:value-of select=
"$schemaRoot"/>
43 <xsl:variable name=
"schemaURL">
44 <xsl:value-of select=
"$xcs"/>
47 <!--************************** TEMPLATES ******************************** -->
48 <!-- ensure that at least root is available -->
49 <xsl:template match=
"/oor:component-data">
52 <xsl:when test=
"string-length($locale)">
53 <xsl:apply-templates select =
"@*" mode=
"locale"/>
54 <xsl:apply-templates select =
"node|prop" mode=
"locale"/>
57 <xsl:apply-templates select =
"@*"/>
58 <xsl:for-each select=
"node|prop">
59 <xsl:variable name=
"component-schema" select=
"document($schemaURL)/oor:component-schema"/>
60 <xsl:apply-templates select=
".">
61 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
62 <xsl:with-param name=
"context" select=
"$component-schema/component/*[@oor:name = current()/@oor:name]"/>
63 <xsl:with-param name=
"find-module" select=
"$module"/>
64 </xsl:apply-templates>
71 <!-- locale dependent data -->
72 <xsl:template match=
"node|prop" mode =
"locale">
74 <xsl:when test=
"$locale=$fallback-locale">
75 <xsl:if test=
"descendant::value[@xml:lang=$locale]/../value[not (@xml:lang)]">
77 <xsl:apply-templates select =
"@*" mode=
"locale"/>
78 <xsl:apply-templates select =
"node|prop|value" mode =
"locale"/>
83 <xsl:if test=
"descendant::value[@xml:lang = $locale]">
85 <xsl:apply-templates select =
"@*" mode=
"locale"/>
86 <xsl:apply-templates select =
"node|prop|value" mode =
"locale"/>
93 <xsl:template match=
"value" mode=
"locale">
94 <xsl:if test=
"@xml:lang=$locale and not(@install:module)">
96 <xsl:apply-templates select =
"@*" mode=
"locale"/>
97 <xsl:apply-templates select=
"node()"/>
102 <xsl:template match =
"@*" mode=
"locale">
106 <!-- suppress all merge instructions -->
107 <xsl:template match =
"@oor:op" mode=
"locale"/>
109 <!-- suppress all module markers -->
110 <xsl:template match =
"@install:module" mode=
"locale"/>
112 <!-- locale independent data -->
114 <!-- handle template references -->
115 <xsl:template name=
"copy-resolve-template">
116 <xsl:param name =
"node-type"/>
117 <xsl:param name =
"schema-type"/>
118 <xsl:param name =
"component-schema"/>
121 <xsl:when test=
"$schema-type='node-ref'">
122 <xsl:apply-templates select=
".">
123 <xsl:with-param name=
"context" select=
"$component-schema/templates/*[@oor:name = $node-type]"/>
124 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
125 </xsl:apply-templates>
127 <xsl:when test=
"$schema-type='set'">
129 <xsl:apply-templates select =
"@*" />
130 <xsl:for-each select=
"node|prop">
131 <xsl:apply-templates select=
".">
132 <xsl:with-param name=
"context" select=
"$component-schema/templates/*[@oor:name = $node-type]"/>
133 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
134 </xsl:apply-templates>
139 <xsl:message terminate=
"yes">ERROR: The schema element for a
<xsl:value-of select=
"$schema-type"/>
140 should not have a node-type.
146 <xsl:template name=
"copy-node">
147 <xsl:param name =
"context"/>
148 <xsl:param name =
"component-schema"/>
151 <!-- look for matching templates in other components -->
152 <xsl:when test=
"$context/@oor:node-type and $context/@oor:component">
153 <xsl:variable name=
"fileURL">
154 <xsl:call-template name=
"composeFileURL">
155 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
156 <xsl:with-param name=
"componentName"><xsl:value-of select=
"$context/@oor:component"/></xsl:with-param>
159 <xsl:call-template name=
"copy-resolve-template">
160 <xsl:with-param name=
"node-type" select=
"$context/@oor:node-type"/>
161 <xsl:with-param name=
"schema-type" select=
"local-name($context)"/>
162 <xsl:with-param name=
"component-schema" select=
"document($fileURL)/oor:component-schema"/>
165 <!-- look for matching templates within the same component -->
166 <xsl:when test=
"$context/@oor:node-type">
167 <xsl:call-template name=
"copy-resolve-template">
168 <xsl:with-param name=
"node-type" select=
"$context/@oor:node-type"/>
169 <xsl:with-param name=
"schema-type" select=
"local-name($context)"/>
170 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
175 <xsl:apply-templates select =
"@*" />
176 <xsl:for-each select=
"node|prop">
177 <xsl:apply-templates select=
".">
178 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
179 <xsl:with-param name=
"context" select=
"$context/*[@oor:name = current()/@oor:name]"/>
180 </xsl:apply-templates>
187 <xsl:template match=
"node">
188 <xsl:param name =
"context"/>
189 <xsl:param name =
"component-schema"/>
191 <xsl:variable name=
"applicable-values" select=
"descendant::value[not (@xml:lang) or (@xml:lang=$fallback-locale) or (@install:module=$module)]"/>
192 <xsl:variable name=
"substantive-nodes" select=
"descendant-or-self::*[(@oor:finalized='true') or (@oor:mandatory='true') or (@oor:op!='modify')]"/>
195 <!-- go ahead, if we are in the active module -->
196 <xsl:when test=
"ancestor-or-self::*/@install:module=$module">
197 <xsl:if test=
"$applicable-values | $substantive-nodes">
198 <xsl:call-template name=
"copy-node">
199 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
200 <xsl:with-param name=
"context" select=
"$context"/>
204 <!-- strip data from wrong module -->
205 <xsl:when test=
"ancestor-or-self::*/@install:module"/>
206 <!-- looking for module -->
207 <xsl:when test=
"$module">
208 <xsl:if test=
"($applicable-values | $substantive-nodes)/ancestor-or-self::*/@install:module=$module">
209 <xsl:call-template name=
"copy-node">
210 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
211 <xsl:with-param name=
"context" select=
"$context"/>
215 <!-- copying non-module data -->
217 <xsl:if test=
"($applicable-values | $substantive-nodes)[not(ancestor-or-self::*/@install:module)]">
218 <xsl:call-template name=
"copy-node">
219 <xsl:with-param name=
"component-schema" select=
"$component-schema"/>
220 <xsl:with-param name=
"context" select=
"$context"/>
227 <xsl:template match=
"prop">
228 <xsl:param name =
"context"/>
230 <xsl:when test=
"$module and not((ancestor-or-self::* | child::value)/@install:module=$module)"/>
231 <xsl:when test=
"not($module) and ancestor-or-self::*/@install:module"/>
232 <xsl:when test=
"not ($context) or @oor:finalized='true' or @oor:op!='modify'">
234 <xsl:apply-templates select =
"@*"/>
235 <xsl:apply-templates select =
"value"/>
238 <xsl:when test=
"value[not (@xml:lang) or @install:module]">
239 <xsl:if test=
"value[not(@install:module) or @install:module=$module]">
240 <!-- copy locale independent values only, if the values differ -->
241 <xsl:variable name=
"isRedundant">
242 <xsl:call-template name=
"isRedundant">
243 <xsl:with-param name=
"schemaval" select=
"$context/value"/>
244 <xsl:with-param name=
"dataval" select=
"value[(not(@xml:lang) or @install:module) and (not(@install:module) or @install:module=$module)]"/>
247 <xsl:if test=
"$isRedundant ='false'">
249 <xsl:apply-templates select =
"@*"/>
250 <xsl:apply-templates select =
"value"/>
257 <xsl:apply-templates select =
"@*"/>
258 <xsl:apply-templates select =
"value" mode=
"fallback-locale"/>
264 <xsl:template match=
"value">
266 <xsl:when test=
"@xml:lang and not(@install:module)"/>
267 <xsl:when test=
"$module and not(ancestor-or-self::*/@install:module=$module)"/>
268 <xsl:when test=
"not($module) and ancestor-or-self::*/@install:module"/>
271 <xsl:apply-templates select =
"@*|node()"/>
277 <xsl:template match=
"value" mode=
"fallback-locale">
278 <xsl:if test=
"@xml:lang=$fallback-locale and not(@install:module)">
280 <xsl:apply-templates select =
"@*|node()"/>
285 <xsl:template match =
"it|unicode">
287 <xsl:apply-templates select =
"@*|node()"/>
291 <xsl:template match =
"@*">
295 <!-- suppress all merge instructions, that are out-of-module -->
296 <xsl:template match =
"@oor:op">
297 <xsl:if test=
"not($module) or ancestor::*/@install:module">
302 <!-- suppress all module markers -->
303 <xsl:template match =
"@install:module"/>
305 <!-- compares two values -->
306 <xsl:template name=
"isRedundant">
307 <xsl:param name =
"schemaval"/>
308 <xsl:param name =
"dataval"/>
310 <xsl:when test=
"not ($dataval)">
311 <xsl:value-of select=
"true()"/>
313 <xsl:when test=
"$dataval/@oor:external">
314 <xsl:value-of select=
"false()"/>
316 <xsl:when test=
"not ($schemaval)">
318 <xsl:when test=
"$dataval/@xsi:nil='true'">
319 <xsl:value-of select=
"true()"/>
322 <xsl:value-of select=
"false()"/>
326 <xsl:when test=
"$schemaval != $dataval">
327 <xsl:value-of select=
"false()"/>
330 <xsl:value-of select=
"true()"/>
335 <xsl:template name=
"composeFileURL">
336 <xsl:param name=
"componentName"/>
337 <xsl:variable name=
"fileURL">
338 <xsl:value-of select=
"$schemaRootURL"/>/
<xsl:value-of select=
"translate($componentName,'.','/')"/><xsl:text>.xcs
</xsl:text>
340 <xsl:value-of select=
"$fileURL"/>
343 <xsl:template match=
"@oor:name">
344 <xsl:attribute name=
"oor:name">
345 <xsl:call-template name=
"replacetwo">
346 <xsl:with-param name=
"input" select=
"current()"/>
347 <xsl:with-param name=
"pattern1" select=
"'@LIBO_SHARE_FOLDER@'"/>
348 <xsl:with-param name=
"replace1" select=
"$LIBO_SHARE_FOLDER"/>
349 <xsl:with-param name=
"pattern2" select=
"'@LIBO_SHARE_HELP_FOLDER@'"/>
350 <xsl:with-param name=
"replace2" select=
"$LIBO_SHARE_HELP_FOLDER"/>
355 <xsl:template match=
"text()">
356 <xsl:call-template name=
"replacetwo">
357 <xsl:with-param name=
"input" select=
"current()"/>
358 <xsl:with-param name=
"pattern1" select=
"'@LIBO_SHARE_FOLDER@'"/>
359 <xsl:with-param name=
"replace1" select=
"$LIBO_SHARE_FOLDER"/>
360 <xsl:with-param name=
"pattern2" select=
"'@LIBO_SHARE_HELP_FOLDER@'"/>
361 <xsl:with-param name=
"replace2" select=
"$LIBO_SHARE_HELP_FOLDER"/>
365 <xsl:template name=
"replace">
366 <xsl:param name=
"input"/>
367 <xsl:param name=
"pattern"/>
368 <xsl:param name=
"replace"/>
370 <xsl:when test=
"contains($input, $pattern)">
371 <xsl:value-of select=
"substring-before($input, $pattern)"/>
372 <xsl:value-of select=
"$replace"/>
373 <xsl:call-template name=
"replace">
375 name=
"input" select=
"substring-after($input, $pattern)"/>
376 <xsl:with-param name=
"pattern" select=
"$pattern"/>
377 <xsl:with-param name=
"replace" select=
"$replace"/>
381 <xsl:value-of select=
"$input"/>
386 <xsl:template name=
"replacetwo">
387 <xsl:param name=
"input"/>
388 <xsl:param name=
"pattern1"/>
389 <xsl:param name=
"replace1"/>
390 <xsl:param name=
"pattern2"/>
391 <xsl:param name=
"replace2"/>
393 <xsl:when test=
"contains($input, $pattern1)">
394 <xsl:call-template name=
"replace">
396 name=
"input" select=
"substring-before($input, $pattern1)"/>
397 <xsl:with-param name=
"pattern" select=
"$pattern2"/>
398 <xsl:with-param name=
"replace" select=
"$replace2"/>
400 <xsl:value-of select=
"$replace1"/>
401 <xsl:call-template name=
"replacetwo">
403 name=
"input" select=
"substring-after($input, $pattern1)"/>
404 <xsl:with-param name=
"pattern1" select=
"$pattern1"/>
405 <xsl:with-param name=
"replace1" select=
"$replace1"/>
406 <xsl:with-param name=
"pattern2" select=
"$pattern2"/>
407 <xsl:with-param name=
"replace2" select=
"$replace2"/>
411 <xsl:call-template name=
"replace">
413 name=
"input" select=
"$input"/>
414 <xsl:with-param name=
"pattern" select=
"$pattern2"/>
415 <xsl:with-param name=
"replace" select=
"$replace2"/>