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