xref: /aoo41x/main/officecfg/util/schema_val.xsl (revision 1e519d8d)
1cdf0e10cSrcweir<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2*1e519d8dSAndrew Rist<!--***********************************************************
3*1e519d8dSAndrew Rist *
4*1e519d8dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
5*1e519d8dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
6*1e519d8dSAndrew Rist * distributed with this work for additional information
7*1e519d8dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
8*1e519d8dSAndrew Rist * to you under the Apache License, Version 2.0 (the
9*1e519d8dSAndrew Rist * "License"); you may not use this file except in compliance
10*1e519d8dSAndrew Rist * with the License.  You may obtain a copy of the License at
11*1e519d8dSAndrew Rist *
12*1e519d8dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
13*1e519d8dSAndrew Rist *
14*1e519d8dSAndrew Rist * Unless required by applicable law or agreed to in writing,
15*1e519d8dSAndrew Rist * software distributed under the License is distributed on an
16*1e519d8dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17*1e519d8dSAndrew Rist * KIND, either express or implied.  See the License for the
18*1e519d8dSAndrew Rist * specific language governing permissions and limitations
19*1e519d8dSAndrew Rist * under the License.
20*1e519d8dSAndrew Rist *
21*1e519d8dSAndrew Rist ***********************************************************-->
22*1e519d8dSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir
25cdf0e10cSrcweir<xsl:transform  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
26cdf0e10cSrcweir		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
27cdf0e10cSrcweir		xmlns:xs="http://www.w3.org/2001/XMLSchema"
28cdf0e10cSrcweir		xmlns:oor="http://openoffice.org/2001/registry"
29cdf0e10cSrcweir		version="1.0">
30cdf0e10cSrcweir
31cdf0e10cSrcweir<!-- Get the correct format -->
32cdf0e10cSrcweir<xsl:output method="xml" indent="yes"/>
33cdf0e10cSrcweir<xsl:namespace-alias stylesheet-prefix="xs" result-prefix="xs"></xsl:namespace-alias>
34cdf0e10cSrcweir
35cdf0e10cSrcweir<!-- Parameter -->
36cdf0e10cSrcweir<xsl:param name="root">../registry/schema</xsl:param>
37cdf0e10cSrcweir<xsl:param name="componentName"/>
38cdf0e10cSrcweir
39cdf0e10cSrcweir	<xsl:template match = "/">
40cdf0e10cSrcweir		<xsl:message terminate="no">CHECKING CONSISTENCY ...</xsl:message>
41cdf0e10cSrcweir		<xsl:apply-templates/>
42cdf0e10cSrcweir	</xsl:template>
43cdf0e10cSrcweir
44cdf0e10cSrcweir<!-- activate attribute templates -->
45cdf0e10cSrcweir	<xsl:template match="group|set|prop">
46cdf0e10cSrcweir		<xsl:apply-templates select="*|@*"/>
47cdf0e10cSrcweir	</xsl:template>
48cdf0e10cSrcweir
49cdf0e10cSrcweir<!-- make sure that missing features are not invoked -->
50cdf0e10cSrcweir	<xsl:template match = "item">
51cdf0e10cSrcweir		<xsl:message terminate="yes">ERROR: multiple template types for sets are NOT supported!</xsl:message>
52cdf0e10cSrcweir	</xsl:template>
53cdf0e10cSrcweir
54cdf0e10cSrcweir	<xsl:template match = "set[@oor:extensible='true']">
55cdf0e10cSrcweir		<xsl:message terminate="yes">ERROR: extensible sets are currently NOT supported!</xsl:message>
56cdf0e10cSrcweir	</xsl:template>
57cdf0e10cSrcweir
58cdf0e10cSrcweir	<xsl:template match = "group[@oor:extensible='true']">
59cdf0e10cSrcweir		<xsl:if test="count(child::set) or count(child::group) or count(child::node-ref)">
60cdf0e10cSrcweir			<xsl:message terminate="yes">ERROR: extensible groups with children are currently NOT supported!</xsl:message>
61cdf0e10cSrcweir		</xsl:if>
62cdf0e10cSrcweir		<xsl:apply-templates select="*|@*"/>
63cdf0e10cSrcweir	</xsl:template>
64cdf0e10cSrcweir
65cdf0e10cSrcweir<!-- Localized info elements (desc/label) are not supported currently -->
66cdf0e10cSrcweir	<xsl:template match="info//*[@xml:lang]">
67cdf0e10cSrcweir		<xsl:message terminate="yes">ERROR: Info elements (desc/label) are currently not localized. Remove xml:lang attributes!</xsl:message>
68cdf0e10cSrcweir	</xsl:template>
69cdf0e10cSrcweir
70cdf0e10cSrcweir<!-- check for duplicate child names -->
71cdf0e10cSrcweir	<xsl:template match="@oor:name">
72cdf0e10cSrcweir        <xsl:variable name="item-name" select="."/>
73cdf0e10cSrcweir		<xsl:if test="../following-sibling::*[@oor:name = $item-name]">
74cdf0e10cSrcweir			<xsl:message terminate="yes">ERROR: Duplicate node name '<xsl:value-of select="$item-name"/>'!</xsl:message>
75cdf0e10cSrcweir		</xsl:if>
76cdf0e10cSrcweir	</xsl:template>
77cdf0e10cSrcweir
78cdf0e10cSrcweir<!-- check if properties of type 'any' do not have a value -->
79cdf0e10cSrcweir	<xsl:template match="prop[@oor:type='oor:any']">
80cdf0e10cSrcweir		<xsl:if test="count(value)">
81cdf0e10cSrcweir			<xsl:message terminate="yes">ERROR: Properties of type 'oor:any' MUST NOT have a value!</xsl:message>
82cdf0e10cSrcweir		</xsl:if>
83cdf0e10cSrcweir		<xsl:apply-templates select="*|@*"/>
84cdf0e10cSrcweir	</xsl:template>
85cdf0e10cSrcweir
86cdf0e10cSrcweir<!-- inhibit (explicit) NIL values -->
87cdf0e10cSrcweir	<xsl:template match="value[@xsi:nil]">
88cdf0e10cSrcweir		<xsl:message terminate="yes">ERROR: xsi:nil is not allowed in schemas !</xsl:message>
89cdf0e10cSrcweir	</xsl:template>
90cdf0e10cSrcweir
91cdf0e10cSrcweir<!-- validate for correct node references -->
92cdf0e10cSrcweir	<xsl:template match="@oor:node-type">
93cdf0e10cSrcweir		<xsl:choose>
94cdf0e10cSrcweir			<xsl:when test="../@oor:component">
95cdf0e10cSrcweir				<xsl:variable name ="file">
96cdf0e10cSrcweir					<xsl:call-template name="locateFile"><xsl:with-param name="componentName" select="../@oor:component"/></xsl:call-template>
97cdf0e10cSrcweir				</xsl:variable>
98cdf0e10cSrcweir				<xsl:if test="not(document($file)/oor:component-schema/templates/*[@oor:name=current()])">
99cdf0e10cSrcweir					<xsl:message terminate="yes">ERROR: node-type '<xsl:value-of select="current()"/>' not found!</xsl:message>
100cdf0e10cSrcweir				</xsl:if>
101cdf0e10cSrcweir			</xsl:when>
102cdf0e10cSrcweir			<xsl:when test="not(/oor:component-schema/templates/*[@oor:name=current()])">
103cdf0e10cSrcweir				<xsl:message terminate="yes">ERROR: node-type '<xsl:value-of select="current()"/>' not found!</xsl:message>
104cdf0e10cSrcweir			</xsl:when>
105cdf0e10cSrcweir		</xsl:choose>
106cdf0e10cSrcweir	</xsl:template>
107cdf0e10cSrcweir
108cdf0e10cSrcweir<!-- validate if file name matches component-name -->
109cdf0e10cSrcweir	<xsl:template match="oor:component-schema">
110cdf0e10cSrcweir		<xsl:variable name ="fullName"><xsl:value-of select="@oor:package"/>.<xsl:value-of select="@oor:name"/></xsl:variable>
111cdf0e10cSrcweir		<xsl:if test="$fullName != $componentName">
112cdf0e10cSrcweir			<xsl:message terminate="yes">ERROR: Component name '<xsl:value-of select="$fullName"/>' does not match with file name!</xsl:message>
113cdf0e10cSrcweir		</xsl:if>
114cdf0e10cSrcweir		<xsl:apply-templates select="*|@*"/>
115cdf0e10cSrcweir	</xsl:template>
116cdf0e10cSrcweir
117cdf0e10cSrcweir
118cdf0e10cSrcweir<!-- locate a component file -->
119cdf0e10cSrcweir	<xsl:template name="locateFile">
120cdf0e10cSrcweir		<xsl:param name="componentName"/>
121cdf0e10cSrcweir		<xsl:variable name ="file"><xsl:value-of select="$root"/>/<xsl:value-of select="translate($componentName,'.','/')"/>.xcs</xsl:variable>
122cdf0e10cSrcweir		<xsl:if	test="not( document($file) )">
123cdf0e10cSrcweir			<xsl:message terminate ="yes">**Error: unable to locate document '<xsl:value-of select="translate($componentName,'.','/')"/>.xcd'</xsl:message>
124cdf0e10cSrcweir		</xsl:if>
125cdf0e10cSrcweir		<xsl:value-of select="$file"/>
126cdf0e10cSrcweir	</xsl:template>
127cdf0e10cSrcweir
128cdf0e10cSrcweir</xsl:transform>
129