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