xref: /trunk/main/officecfg/util/data_val.xsl (revision cdf0e10c)
1*cdf0e10cSrcweir<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2*cdf0e10cSrcweir<!--***********************************************************************
3*cdf0e10cSrcweir *
4*cdf0e10cSrcweir  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5*cdf0e10cSrcweir
6*cdf0e10cSrcweir  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir
8*cdf0e10cSrcweir  OpenOffice.org - a multi-platform office productivity suite
9*cdf0e10cSrcweir
10*cdf0e10cSrcweir  This file is part of OpenOffice.org.
11*cdf0e10cSrcweir
12*cdf0e10cSrcweir  OpenOffice.org is free software: you can redistribute it and/or modify
13*cdf0e10cSrcweir  it under the terms of the GNU Lesser General Public License version 3
14*cdf0e10cSrcweir  only, as published by the Free Software Foundation.
15*cdf0e10cSrcweir
16*cdf0e10cSrcweir  OpenOffice.org is distributed in the hope that it will be useful,
17*cdf0e10cSrcweir  but WITHOUT ANY WARRANTY; without even the implied warranty of
18*cdf0e10cSrcweir  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19*cdf0e10cSrcweir  GNU Lesser General Public License version 3 for more details
20*cdf0e10cSrcweir  (a copy is included in the LICENSE file that accompanied this code).
21*cdf0e10cSrcweir
22*cdf0e10cSrcweir  You should have received a copy of the GNU Lesser General Public License
23*cdf0e10cSrcweir  version 3 along with OpenOffice.org.  If not, see
24*cdf0e10cSrcweir  <http://www.openoffice.org/license.html>
25*cdf0e10cSrcweir  for a copy of the LGPLv3 License.
26*cdf0e10cSrcweir
27*cdf0e10cSrcweir ************************************************************************ -->
28*cdf0e10cSrcweir
29*cdf0e10cSrcweir<!-- ************************************************************************************** -->
30*cdf0e10cSrcweir<!-- * Transformation from New Format XCS & XCU to schema description					*** -->
31*cdf0e10cSrcweir<!-- ************************************************************************************** -->
32*cdf0e10cSrcweir<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33*cdf0e10cSrcweir				xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
34*cdf0e10cSrcweir				xmlns:xs="http://www.w3.org/2001/XMLSchema"
35*cdf0e10cSrcweir				xmlns:oor="http://openoffice.org/2001/registry"
36*cdf0e10cSrcweir				xmlns:install="http://openoffice.org/2004/installation">
37*cdf0e10cSrcweir
38*cdf0e10cSrcweir<!-- Get the correct format -->
39*cdf0e10cSrcweir<xsl:output method="xml" indent="yes" />
40*cdf0e10cSrcweir
41*cdf0e10cSrcweir<xsl:param name="xcs"/>
42*cdf0e10cSrcweir<xsl:param name="schemaRoot">.</xsl:param>
43*cdf0e10cSrcweir
44*cdf0e10cSrcweir<xsl:variable name="schemaRootURL">
45*cdf0e10cSrcweir    <xsl:value-of select="$schemaRoot"/>
46*cdf0e10cSrcweir</xsl:variable>
47*cdf0e10cSrcweir<xsl:variable name="schemaURL">
48*cdf0e10cSrcweir    <xsl:value-of select="$xcs"/>
49*cdf0e10cSrcweir</xsl:variable>
50*cdf0e10cSrcweir
51*cdf0e10cSrcweir<!-- ************************************** -->
52*cdf0e10cSrcweir<!-- * oor:component-data							*** -->
53*cdf0e10cSrcweir<!-- ************************************** -->
54*cdf0e10cSrcweir	<xsl:template match="/oor:component-data">
55*cdf0e10cSrcweir        <xsl:variable name="component-schema" select="document($schemaURL)/oor:component-schema"/>
56*cdf0e10cSrcweir		<xsl:for-each select="node|prop">
57*cdf0e10cSrcweir			<xsl:apply-templates select=".">
58*cdf0e10cSrcweir				<xsl:with-param name="context" select="$component-schema/component/*[@oor:name = current()/@oor:name]"/>
59*cdf0e10cSrcweir				<xsl:with-param name="component-schema" select="$component-schema"/>
60*cdf0e10cSrcweir			</xsl:apply-templates>
61*cdf0e10cSrcweir		</xsl:for-each>
62*cdf0e10cSrcweir	</xsl:template>
63*cdf0e10cSrcweir
64*cdf0e10cSrcweir<!-- ****************************************** -->
65*cdf0e10cSrcweir<!-- * handle template references           *** -->
66*cdf0e10cSrcweir<!-- ****************************************** -->
67*cdf0e10cSrcweir	<xsl:template name="resolve-template">
68*cdf0e10cSrcweir		<xsl:param name = "node-type"/>
69*cdf0e10cSrcweir		<xsl:param name = "schema-type"/>
70*cdf0e10cSrcweir		<xsl:param name = "component-schema"/>
71*cdf0e10cSrcweir		<xsl:variable name = "path">
72*cdf0e10cSrcweir			<xsl:call-template name="collectPath"/>
73*cdf0e10cSrcweir		</xsl:variable>
74*cdf0e10cSrcweir
75*cdf0e10cSrcweir		<xsl:if test="not ($component-schema)">
76*cdf0e10cSrcweir			<xsl:message terminate="yes">ERROR: Template '<xsl:value-of select="$node-type"/>',
77*cdf0e10cSrcweir                                         referenced from node '<xsl:value-of select="$path"/>'
78*cdf0e10cSrcweir                                         does not exist in schema!
79*cdf0e10cSrcweir            </xsl:message>
80*cdf0e10cSrcweir		</xsl:if>
81*cdf0e10cSrcweir
82*cdf0e10cSrcweir        <xsl:choose>
83*cdf0e10cSrcweir            <xsl:when test="$schema-type='node-ref'">
84*cdf0e10cSrcweir                <xsl:apply-templates select=".">
85*cdf0e10cSrcweir                    <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
86*cdf0e10cSrcweir                    <xsl:with-param name="component-schema" select="$component-schema"/>
87*cdf0e10cSrcweir                </xsl:apply-templates>
88*cdf0e10cSrcweir            </xsl:when>
89*cdf0e10cSrcweir            <xsl:when test="$schema-type='set'">
90*cdf0e10cSrcweir                <xsl:for-each select="node|prop">
91*cdf0e10cSrcweir                    <xsl:apply-templates select=".">
92*cdf0e10cSrcweir                        <xsl:with-param name="context" select="$component-schema/templates/*[@oor:name = $node-type]"/>
93*cdf0e10cSrcweir                        <xsl:with-param name="component-schema" select="$component-schema"/>
94*cdf0e10cSrcweir                    </xsl:apply-templates>
95*cdf0e10cSrcweir                </xsl:for-each>
96*cdf0e10cSrcweir            </xsl:when>
97*cdf0e10cSrcweir            <xsl:otherwise>
98*cdf0e10cSrcweir                <xsl:message terminate="yes">ERROR: The schema element for node <xsl:value-of select="$path"/>
99*cdf0e10cSrcweir                                              is a <xsl:value-of select="$schema-type"/> and should not have a node-type.
100*cdf0e10cSrcweir                </xsl:message>
101*cdf0e10cSrcweir            </xsl:otherwise>
102*cdf0e10cSrcweir        </xsl:choose>
103*cdf0e10cSrcweir    </xsl:template>
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir<!-- ****************************************** -->
106*cdf0e10cSrcweir<!-- * node									*** -->
107*cdf0e10cSrcweir<!-- ****************************************** -->
108*cdf0e10cSrcweir	<xsl:template match="node">
109*cdf0e10cSrcweir		<xsl:param name = "context"/>
110*cdf0e10cSrcweir		<xsl:param name = "component-schema"/>
111*cdf0e10cSrcweir		<xsl:variable name = "path">
112*cdf0e10cSrcweir			<xsl:call-template name="collectPath"/>
113*cdf0e10cSrcweir		</xsl:variable>
114*cdf0e10cSrcweir
115*cdf0e10cSrcweir		<xsl:if test="not ($context)">
116*cdf0e10cSrcweir			<xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message>
117*cdf0e10cSrcweir		</xsl:if>
118*cdf0e10cSrcweir
119*cdf0e10cSrcweir        <xsl:call-template name="checkModule"/>
120*cdf0e10cSrcweir        <xsl:call-template name="checkDuplicates"/>
121*cdf0e10cSrcweir
122*cdf0e10cSrcweir		<xsl:choose>
123*cdf0e10cSrcweir			<!-- look for matching templates in other components -->
124*cdf0e10cSrcweir			<xsl:when test="$context/@oor:node-type and $context/@oor:component">
125*cdf0e10cSrcweir				<xsl:variable name="fileURL">
126*cdf0e10cSrcweir					<xsl:call-template name="composeFileURL">
127*cdf0e10cSrcweir						<xsl:with-param name="componentName"><xsl:value-of select="$context/@oor:component"/></xsl:with-param>
128*cdf0e10cSrcweir					</xsl:call-template>
129*cdf0e10cSrcweir				</xsl:variable>
130*cdf0e10cSrcweir
131*cdf0e10cSrcweir                <xsl:call-template name="resolve-template">
132*cdf0e10cSrcweir                    <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
133*cdf0e10cSrcweir                    <xsl:with-param name="schema-type" select="local-name($context)"/>
134*cdf0e10cSrcweir                    <xsl:with-param name="component-schema" select="document($fileURL)/oor:component-schema"/>
135*cdf0e10cSrcweir                </xsl:call-template>
136*cdf0e10cSrcweir			</xsl:when>
137*cdf0e10cSrcweir			<!-- look for matching templates within the same component -->
138*cdf0e10cSrcweir			<xsl:when test="$context/@oor:node-type">
139*cdf0e10cSrcweir                <xsl:call-template name="resolve-template">
140*cdf0e10cSrcweir                    <xsl:with-param name="node-type" select="$context/@oor:node-type"/>
141*cdf0e10cSrcweir                    <xsl:with-param name="schema-type" select="local-name($context)"/>
142*cdf0e10cSrcweir                    <xsl:with-param name="component-schema" select="$component-schema"/>
143*cdf0e10cSrcweir                </xsl:call-template>
144*cdf0e10cSrcweir			</xsl:when>
145*cdf0e10cSrcweir			<!-- is the node extensible ? -->
146*cdf0e10cSrcweir			<xsl:when test="$context/@oor:extensible='true'">
147*cdf0e10cSrcweir				<xsl:for-each select="node|prop">
148*cdf0e10cSrcweir					<xsl:apply-templates select="." mode="extensible">
149*cdf0e10cSrcweir					    <xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/>
150*cdf0e10cSrcweir                        <xsl:with-param name="component-schema" select="$component-schema"/>
151*cdf0e10cSrcweir				    </xsl:apply-templates>
152*cdf0e10cSrcweir				</xsl:for-each>
153*cdf0e10cSrcweir			</xsl:when>
154*cdf0e10cSrcweir			<xsl:otherwise>
155*cdf0e10cSrcweir				<xsl:for-each select="node|prop">
156*cdf0e10cSrcweir					<xsl:apply-templates select=".">
157*cdf0e10cSrcweir						<xsl:with-param name="context" select="$context/*[@oor:name = current()/@oor:name]"/>
158*cdf0e10cSrcweir                        <xsl:with-param name="component-schema" select="$component-schema"/>
159*cdf0e10cSrcweir					</xsl:apply-templates>
160*cdf0e10cSrcweir				</xsl:for-each>
161*cdf0e10cSrcweir			</xsl:otherwise>
162*cdf0e10cSrcweir		</xsl:choose>
163*cdf0e10cSrcweir	</xsl:template>
164*cdf0e10cSrcweir
165*cdf0e10cSrcweir<!-- ****************************************** -->
166*cdf0e10cSrcweir<!-- * prop									*** -->
167*cdf0e10cSrcweir<!-- ****************************************** -->
168*cdf0e10cSrcweir	<xsl:template match="prop">
169*cdf0e10cSrcweir		<xsl:param name = "context"/>
170*cdf0e10cSrcweir		<xsl:variable name = "path">
171*cdf0e10cSrcweir			<xsl:call-template name="collectPath"/>
172*cdf0e10cSrcweir		</xsl:variable>
173*cdf0e10cSrcweir
174*cdf0e10cSrcweir
175*cdf0e10cSrcweir		<xsl:if test="not ($context)">
176*cdf0e10cSrcweir			<xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema !</xsl:message>
177*cdf0e10cSrcweir		</xsl:if>
178*cdf0e10cSrcweir
179*cdf0e10cSrcweir		<xsl:if test="@oor:op">
180*cdf0e10cSrcweir			<xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>' !</xsl:message>
181*cdf0e10cSrcweir		</xsl:if>
182*cdf0e10cSrcweir
183*cdf0e10cSrcweir        <xsl:call-template name="checkModule"/>
184*cdf0e10cSrcweir        <xsl:call-template name="checkDuplicates"/>
185*cdf0e10cSrcweir
186*cdf0e10cSrcweir        <xsl:apply-templates />
187*cdf0e10cSrcweir	</xsl:template>
188*cdf0e10cSrcweir
189*cdf0e10cSrcweir<!-- ****************************************** -->
190*cdf0e10cSrcweir<!-- * value									*** -->
191*cdf0e10cSrcweir<!-- ****************************************** -->
192*cdf0e10cSrcweir	<xsl:template match="value">
193*cdf0e10cSrcweir        <xsl:call-template name="checkModule"/>
194*cdf0e10cSrcweir
195*cdf0e10cSrcweir        <xsl:if test="@install:module">
196*cdf0e10cSrcweir            <xsl:variable name = "path">
197*cdf0e10cSrcweir                <xsl:call-template name="collectPath"/>
198*cdf0e10cSrcweir            </xsl:variable>
199*cdf0e10cSrcweir            <xsl:variable name = "module" select="@install:module"/>
200*cdf0e10cSrcweir            <xsl:variable name = "lang" select="@xml:lang"/>
201*cdf0e10cSrcweir
202*cdf0e10cSrcweir            <xsl:if test="following-sibling::value[@install:module=$module and @xml:lang=$lang]">
203*cdf0e10cSrcweir                <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has multiple values for module <xsl:value-of select="$module"/> and locale <xsl:value-of select="$lang"/>!</xsl:message>
204*cdf0e10cSrcweir            </xsl:if>
205*cdf0e10cSrcweir            <xsl:if test="not(preceding-sibling::value/@install:module)">
206*cdf0e10cSrcweir                <xsl:message>ATTENTION: Property '<xsl:value-of select="$path"/>' has different values for different modules. Make sure the modules are mutually exclusive!</xsl:message>
207*cdf0e10cSrcweir            </xsl:if>
208*cdf0e10cSrcweir        </xsl:if>
209*cdf0e10cSrcweir	</xsl:template>
210*cdf0e10cSrcweir
211*cdf0e10cSrcweir<!-- ****************************************** -->
212*cdf0e10cSrcweir<!-- * node (mode:extensible) - not supported * -->
213*cdf0e10cSrcweir<!-- ****************************************** -->
214*cdf0e10cSrcweir	<xsl:template match="node" mode="extensible">
215*cdf0e10cSrcweir		<xsl:variable name = "path">
216*cdf0e10cSrcweir			<xsl:call-template name="collectPath"/>
217*cdf0e10cSrcweir		</xsl:variable>
218*cdf0e10cSrcweir
219*cdf0e10cSrcweir        <xsl:message terminate="yes">ERROR: Node '<xsl:value-of select="$path"/>' is within an extensible node!</xsl:message>
220*cdf0e10cSrcweir    </xsl:template>
221*cdf0e10cSrcweir<!-- ****************************************** -->
222*cdf0e10cSrcweir<!-- * prop (mode:extensible)				*** -->
223*cdf0e10cSrcweir<!-- ****************************************** -->
224*cdf0e10cSrcweir	<xsl:template match="prop" mode="extensible">
225*cdf0e10cSrcweir		<xsl:param name = "context"/>
226*cdf0e10cSrcweir		<xsl:variable name = "path">
227*cdf0e10cSrcweir			<xsl:call-template name="collectPath"/>
228*cdf0e10cSrcweir		</xsl:variable>
229*cdf0e10cSrcweir
230*cdf0e10cSrcweir        <xsl:choose>
231*cdf0e10cSrcweir            <xsl:when test="not(@oor:op)">
232*cdf0e10cSrcweir		        <xsl:if test="not ($context)">
233*cdf0e10cSrcweir			        <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not exist in schema!</xsl:message>
234*cdf0e10cSrcweir		        </xsl:if>
235*cdf0e10cSrcweir		    </xsl:when>
236*cdf0e10cSrcweir            <xsl:when test="@oor:op='replace'">
237*cdf0e10cSrcweir		        <xsl:if test="not (@oor:type)">
238*cdf0e10cSrcweir			        <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' does not have a type!</xsl:message>
239*cdf0e10cSrcweir		        </xsl:if>
240*cdf0e10cSrcweir		    </xsl:when>
241*cdf0e10cSrcweir		    <xsl:otherwise>
242*cdf0e10cSrcweir			    <xsl:message terminate="yes">ERROR: Property '<xsl:value-of select="$path"/>' has unexpected operation '<xsl:value-of select="@oor:op"/>'!</xsl:message>
243*cdf0e10cSrcweir		    </xsl:otherwise>
244*cdf0e10cSrcweir        </xsl:choose>
245*cdf0e10cSrcweir
246*cdf0e10cSrcweir        <xsl:call-template name="checkModule"/>
247*cdf0e10cSrcweir        <xsl:call-template name="checkDuplicates"/>
248*cdf0e10cSrcweir	</xsl:template>
249*cdf0e10cSrcweir
250*cdf0e10cSrcweir
251*cdf0e10cSrcweir<!-- ************************************* -->
252*cdf0e10cSrcweir<!-- * checkDuplicates  			   *** -->
253*cdf0e10cSrcweir<!-- ************************************* -->
254*cdf0e10cSrcweir	<xsl:template name="checkDuplicates">
255*cdf0e10cSrcweir        <xsl:variable name="item-name" select="@oor:name"/>
256*cdf0e10cSrcweir		<xsl:if test="following-sibling::*[@oor:name = $item-name]">
257*cdf0e10cSrcweir            <xsl:variable name = "path">
258*cdf0e10cSrcweir                <xsl:call-template name="collectPath"/>
259*cdf0e10cSrcweir            </xsl:variable>
260*cdf0e10cSrcweir			<xsl:message terminate="yes">ERROR: Duplicate node/prop '<xsl:value-of select="$path"/>'!</xsl:message>
261*cdf0e10cSrcweir		</xsl:if>
262*cdf0e10cSrcweir	</xsl:template>
263*cdf0e10cSrcweir
264*cdf0e10cSrcweir
265*cdf0e10cSrcweir<!-- ************************************* -->
266*cdf0e10cSrcweir<!-- * checkModule					   *** -->
267*cdf0e10cSrcweir<!-- ************************************* -->
268*cdf0e10cSrcweir	<xsl:template name="checkModule">
269*cdf0e10cSrcweir		<xsl:if test="@install:module">
270*cdf0e10cSrcweir            <xsl:if test="ancestor::*[@install:module]">
271*cdf0e10cSrcweir                <xsl:message terminate="yes">ERROR: Nested modules are not supported.  Found module '<xsl:value-of select="@install:module"/>' within module '<xsl:value-of select="ancestor::*/@install:module"/>'!
272*cdf0e10cSrcweir                </xsl:message>
273*cdf0e10cSrcweir            </xsl:if>
274*cdf0e10cSrcweir		</xsl:if>
275*cdf0e10cSrcweir	</xsl:template>
276*cdf0e10cSrcweir
277*cdf0e10cSrcweir<!-- ************************************* -->
278*cdf0e10cSrcweir<!-- * collectPath					   *** -->
279*cdf0e10cSrcweir<!-- ************************************* -->
280*cdf0e10cSrcweir	<xsl:template name="collectPath">
281*cdf0e10cSrcweir		<xsl:for-each select="ancestor-or-self::node()[@oor:name]">
282*cdf0e10cSrcweir			<xsl:text>/</xsl:text><xsl:value-of select="@oor:name"/>
283*cdf0e10cSrcweir		</xsl:for-each>
284*cdf0e10cSrcweir	</xsl:template>
285*cdf0e10cSrcweir
286*cdf0e10cSrcweir
287*cdf0e10cSrcweir<!-- ****************************** -->
288*cdf0e10cSrcweir<!-- * composeFileURL			*** -->
289*cdf0e10cSrcweir<!-- ****************************** -->
290*cdf0e10cSrcweir	<xsl:template name="composeFileURL">
291*cdf0e10cSrcweir		<xsl:param name="componentName"/>
292*cdf0e10cSrcweir		<xsl:variable name="fileURL">
293*cdf0e10cSrcweir			<xsl:value-of select="$schemaRootURL"/>/<xsl:value-of select="translate($componentName,'.','/')"/><xsl:text>.xcs</xsl:text>
294*cdf0e10cSrcweir		</xsl:variable>
295*cdf0e10cSrcweir		<xsl:value-of select="$fileURL"/>
296*cdf0e10cSrcweir	</xsl:template>
297*cdf0e10cSrcweir
298*cdf0e10cSrcweir
299*cdf0e10cSrcweir</xsl:transform>
300*cdf0e10cSrcweir
301