update dev300-m58
[ooovba.git] / officecfg / util / alllang.xsl
blob47ae081659286134a8e39a928801769b5d234e70
1 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2 <!--***********************************************************************
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 Copyright 2008 by Sun Microsystems, Inc.
8 OpenOffice.org - a multi-platform office productivity suite
10 $RCSfile: alllang.xsl,v $
12 $Revision: 1.14 $
14 This file is part of OpenOffice.org.
16 OpenOffice.org is free software: you can redistribute it and/or modify
17 it under the terms of the GNU Lesser General Public License version 3
18 only, as published by the Free Software Foundation.
20 OpenOffice.org is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU Lesser General Public License version 3 for more details
24 (a copy is included in the LICENSE file that accompanied this code).
26 You should have received a copy of the GNU Lesser General Public License
27 version 3 along with OpenOffice.org. If not, see
28 <http://www.openoffice.org/license.html>
29 for a copy of the LGPLv3 License.
31 ************************************************************************ -->
33 <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
34 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
35 xmlns:xs="http://www.w3.org/2001/XMLSchema"
36 xmlns:oor="http://openoffice.org/2001/registry"
37 xmlns:install="http://openoffice.org/2004/installation"
38 exclude-result-prefixes="install">
40 <!-- Get the correct format -->
41 <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
43 <!--************************** PARAMETER ******************************** -->
44 <xsl:param name="locale"/>
45 <xsl:param name="module"/>
46 <xsl:param name="xcs"/>
47 <xsl:param name="schemaRoot">.</xsl:param>
48 <xsl:param name="fallback-locale">en-US</xsl:param>
50 <xsl:variable name="schemaRootURL">
51 <xsl:value-of select="$schemaRoot"/>
52 </xsl:variable>
53 <xsl:variable name="schemaURL">
54 <xsl:value-of select="$xcs"/>
55 </xsl:variable>
57 <!--************************** TEMPLATES ******************************** -->
58 <!-- ensure that at least root is available -->
59 <xsl:template match="/oor:component-data">
60 <xsl:copy>
61 <xsl:choose>
62 <xsl:when test="string-length($locale)">
63 <xsl:apply-templates select = "@*" mode="locale"/>
64 <xsl:apply-templates mode="locale"/>
65 </xsl:when>
66 <xsl:otherwise>
67 <xsl:apply-templates select = "@*"/>
68 <xsl:for-each select="node|prop">
69 <xsl:variable name="component-schema" select="document($schemaURL)/oor:component-schema"/>
70 <xsl:apply-templates select=".">
71 <xsl:with-param name="component-schema" select="$component-schema"/>
72 <xsl:with-param name="context" select="$component-schema/component/*[@oor:name = current()/@oor:name]"/>
73 <xsl:with-param name="find-module" select="$module"/>
74 </xsl:apply-templates>
75 </xsl:for-each>
76 </xsl:otherwise>
77 </xsl:choose>
78 </xsl:copy>
79 </xsl:template>
81 <!-- locale dependent data -->
82 <xsl:template match="node|prop" mode = "locale">
83 <xsl:choose>
84 <xsl:when test="$locale=$fallback-locale">
85 <xsl:if test="descendant::value[@xml:lang=$locale]/../value[not (@xml:lang)]">
86 <xsl:copy>
87 <xsl:apply-templates select = "@*" mode="locale"/>
88 <xsl:apply-templates mode = "locale"/>
89 </xsl:copy>
90 </xsl:if>
91 </xsl:when>
92 <xsl:otherwise>
93 <xsl:if test="descendant::value[@xml:lang = $locale]">
94 <xsl:copy>
95 <xsl:apply-templates select = "@*" mode="locale"/>
96 <xsl:apply-templates mode = "locale"/>
97 </xsl:copy>
98 </xsl:if>
99 </xsl:otherwise>
100 </xsl:choose>
101 </xsl:template>
103 <xsl:template match="value" mode="locale">
104 <xsl:if test="@xml:lang=$locale and not(@install:module)">
105 <xsl:copy>
106 <xsl:apply-templates select = "@*" mode="locale"/>
107 <xsl:value-of select="."/>
108 </xsl:copy>
109 </xsl:if>
110 </xsl:template>
112 <xsl:template match = "@*" mode="locale">
113 <xsl:copy/>
114 </xsl:template>
116 <!-- suppress all merge instructions -->
117 <xsl:template match = "@oor:op" mode="locale"/>
119 <!-- suppress all module markers -->
120 <xsl:template match = "@install:module" mode="locale"/>
122 <!-- locale independent data -->
124 <!-- handle template references -->
125 <xsl:template name="copy-resolve-template">
126 <xsl:param name = "node-type"/>
127 <xsl:param name = "schema-type"/>
128 <xsl:param name = "component-schema"/>
130 <xsl:choose>
131 <xsl:when test="$schema-type='node-ref'">
132 <xsl:apply-templates select=".">
133 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
134 <xsl:with-param name="component-schema" select="$component-schema"/>
135 </xsl:apply-templates>
136 </xsl:when>
137 <xsl:when test="$schema-type='set'">
138 <xsl:copy>
139 <xsl:apply-templates select = "@*" />
140 <xsl:for-each select="node|prop">
141 <xsl:apply-templates select=".">
142 <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
143 <xsl:with-param name="component-schema" select="$component-schema"/>
144 </xsl:apply-templates>
145 </xsl:for-each>
146 </xsl:copy>
147 </xsl:when>
148 <xsl:otherwise>
149 <xsl:message terminate="yes">ERROR: The schema element for a <xsl:value-of select="$schema-type"/>
150 should not have a node-type.
151 </xsl:message>
152 </xsl:otherwise>
153 </xsl:choose>
154 </xsl:template>
156 <xsl:template name="copy-node">
157 <xsl:param name = "context"/>
158 <xsl:param name = "component-schema"/>
160 <xsl:choose>
161 <!-- look for matching templates in other components -->
162 <xsl:when test="$context/@oor:node-type and $context/@oor:component">
163 <xsl:variable name="fileURL">
164 <xsl:call-template name="composeFileURL">
165 <xsl:with-param name="component-schema" select="$component-schema"/>
166 <xsl:with-param name="componentName"><xsl:value-of select="$context/@oor:component"/></xsl:with-param>
167 </xsl:call-template>
168 </xsl:variable>
169 <xsl:call-template name="copy-resolve-template">
170 <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
171 <xsl:with-param name="schema-type" select="local-name($context)"/>
172 <xsl:with-param name="component-schema" select="document($fileURL)/oor:component-schema"/>
173 </xsl:call-template>
174 </xsl:when>
175 <!-- look for matching templates within the same component -->
176 <xsl:when test="$context/@oor:node-type">
177 <xsl:call-template name="copy-resolve-template">
178 <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
179 <xsl:with-param name="schema-type" select="local-name($context)"/>
180 <xsl:with-param name="component-schema" select="$component-schema"/>
181 </xsl:call-template>
182 </xsl:when>
183 <xsl:otherwise>
184 <xsl:copy>
185 <xsl:apply-templates select = "@*" />
186 <xsl:for-each select="node|prop">
187 <xsl:apply-templates select=".">
188 <xsl:with-param name="component-schema" select="$component-schema"/>
189 <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/>
190 </xsl:apply-templates>
191 </xsl:for-each>
192 </xsl:copy>
193 </xsl:otherwise>
194 </xsl:choose>
195 </xsl:template>
197 <xsl:template match="node">
198 <xsl:param name = "context"/>
199 <xsl:param name = "component-schema"/>
201 <xsl:variable name="applicable-values" select="descendant::value[not (@xml:lang) or (@xml:lang=$fallback-locale) or (@install:module=$module)]"/>
202 <xsl:variable name="substantive-nodes" select="descendant-or-self::*[(@oor:finalized='true') or (@oor:mandatory='true') or (@oor:op!='modify')]"/>
204 <xsl:choose>
205 <!-- go ahead, if we are in the active module -->
206 <xsl:when test="ancestor-or-self::*/@install:module=$module">
207 <xsl:if test="$applicable-values | $substantive-nodes">
208 <xsl:call-template name="copy-node">
209 <xsl:with-param name="component-schema" select="$component-schema"/>
210 <xsl:with-param name="context" select="$context"/>
211 </xsl:call-template>
212 </xsl:if>
213 </xsl:when>
214 <!-- strip data from wrong module -->
215 <xsl:when test="ancestor-or-self::*/@install:module"/>
216 <!-- looking for module -->
217 <xsl:when test="$module">
218 <xsl:if test="($applicable-values | $substantive-nodes)/ancestor-or-self::*/@install:module=$module">
219 <xsl:call-template name="copy-node">
220 <xsl:with-param name="component-schema" select="$component-schema"/>
221 <xsl:with-param name="context" select="$context"/>
222 </xsl:call-template>
223 </xsl:if>
224 </xsl:when>
225 <!-- copying non-module data -->
226 <xsl:otherwise>
227 <xsl:if test="($applicable-values | $substantive-nodes)[not(ancestor-or-self::*/@install:module)]">
228 <xsl:call-template name="copy-node">
229 <xsl:with-param name="component-schema" select="$component-schema"/>
230 <xsl:with-param name="context" select="$context"/>
231 </xsl:call-template>
232 </xsl:if>
233 </xsl:otherwise>
234 </xsl:choose>
235 </xsl:template>
237 <xsl:template match="prop">
238 <xsl:param name = "context"/>
239 <xsl:choose>
240 <xsl:when test="$module and not((ancestor-or-self::* | child::value)/@install:module=$module)"/>
241 <xsl:when test="not($module) and ancestor-or-self::*/@install:module"/>
242 <xsl:when test="not ($context) or @oor:finalized='true' or @oor:op!='modify'">
243 <xsl:copy>
244 <xsl:apply-templates select = "@*"/>
245 <xsl:apply-templates select = "value"/>
246 </xsl:copy>
247 </xsl:when>
248 <xsl:when test="value[not (@xml:lang) or @install:module]">
249 <xsl:if test="value[not(@install:module) or @install:module=$module]">
250 <!-- copy locale independent values only, if the values differ -->
251 <xsl:variable name="isRedundant">
252 <xsl:call-template name="isRedundant">
253 <xsl:with-param name="schemaval" select="$context/value"/>
254 <xsl:with-param name="dataval" select="value[(not(@xml:lang) or @install:module) and (not(@install:module) or @install:module=$module)]"/>
255 </xsl:call-template>
256 </xsl:variable>
257 <xsl:if test="$isRedundant ='false'">
258 <xsl:copy>
259 <xsl:apply-templates select = "@*"/>
260 <xsl:apply-templates select = "value"/>
261 </xsl:copy>
262 </xsl:if>
263 </xsl:if>
264 </xsl:when>
265 <xsl:otherwise>
266 <xsl:copy>
267 <xsl:apply-templates select = "@*"/>
268 <xsl:apply-templates select = "value" mode="fallback-locale"/>
269 </xsl:copy>
270 </xsl:otherwise>
271 </xsl:choose>
272 </xsl:template>
274 <xsl:template match="value">
275 <xsl:choose>
276 <xsl:when test="@xml:lang and not(@install:module)"/>
277 <xsl:when test="$module and not(ancestor-or-self::*/@install:module=$module)"/>
278 <xsl:when test="not($module) and ancestor-or-self::*/@install:module"/>
279 <xsl:otherwise>
280 <xsl:copy>
281 <xsl:apply-templates select = "@*"/>
282 <xsl:value-of select="."/>
283 </xsl:copy>
284 </xsl:otherwise>
285 </xsl:choose>
286 </xsl:template>
288 <xsl:template match="value" mode="fallback-locale">
289 <xsl:if test="@xml:lang=$fallback-locale and not(@install:module)">
290 <xsl:copy>
291 <xsl:apply-templates select = "@*"/>
292 <xsl:value-of select="."/>
293 </xsl:copy>
294 </xsl:if>
295 </xsl:template>
297 <xsl:template match = "@*">
298 <xsl:copy/>
299 </xsl:template>
301 <!-- suppress all merge instructions, that are out-of-module -->
302 <xsl:template match = "@oor:op">
303 <xsl:if test="not($module) or ancestor::*/@install:module">
304 <xsl:copy/>
305 </xsl:if>
306 </xsl:template>
308 <!-- suppress all module markers -->
309 <xsl:template match = "@install:module"/>
311 <!-- compares two values -->
312 <xsl:template name="isRedundant">
313 <xsl:param name = "schemaval"/>
314 <xsl:param name = "dataval"/>
315 <xsl:choose>
316 <xsl:when test="not ($dataval)">
317 <xsl:value-of select="true()"/>
318 </xsl:when>
319 <xsl:when test="not ($schemaval)">
320 <xsl:choose>
321 <xsl:when test="$dataval/@xsi:nil='true'">
322 <xsl:value-of select="true()"/>
323 </xsl:when>
324 <xsl:otherwise>
325 <xsl:value-of select="false()"/>
326 </xsl:otherwise>
327 </xsl:choose>
328 </xsl:when>
329 <xsl:when test="$schemaval != $dataval">
330 <xsl:value-of select="false()"/>
331 </xsl:when>
332 <xsl:otherwise>
333 <xsl:value-of select="true()"/>
334 </xsl:otherwise>
335 </xsl:choose>
336 </xsl:template>
338 <xsl:template name="composeFileURL">
339 <xsl:param name="componentName"/>
340 <xsl:variable name="fileURL">
341 <xsl:value-of select="$schemaRootURL"/>/<xsl:value-of select="translate($componentName,'.','/')"/><xsl:text>.xcs</xsl:text>
342 </xsl:variable>
343 <xsl:value-of select="$fileURL"/>
344 </xsl:template>
346 </xsl:transform>