xref: /aoo4110/main/officecfg/util/schema_val.xsl (revision b1cdbd2c)
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"
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		version="1.0">
30
31<!-- Get the correct format -->
32<xsl:output method="xml" indent="yes"/>
33<xsl:namespace-alias stylesheet-prefix="xs" result-prefix="xs"></xsl:namespace-alias>
34
35<!-- Parameter -->
36<xsl:param name="root">../registry/schema</xsl:param>
37<xsl:param name="componentName"/>
38
39	<xsl:template match = "/">
40		<xsl:message terminate="no">CHECKING CONSISTENCY ...</xsl:message>
41		<xsl:apply-templates/>
42	</xsl:template>
43
44<!-- activate attribute templates -->
45	<xsl:template match="group|set|prop">
46		<xsl:apply-templates select="*|@*"/>
47	</xsl:template>
48
49<!-- make sure that missing features are not invoked -->
50	<xsl:template match = "item">
51		<xsl:message terminate="yes">ERROR: multiple template types for sets are NOT supported!</xsl:message>
52	</xsl:template>
53
54	<xsl:template match = "set[@oor:extensible='true']">
55		<xsl:message terminate="yes">ERROR: extensible sets are currently NOT supported!</xsl:message>
56	</xsl:template>
57
58	<xsl:template match = "group[@oor:extensible='true']">
59		<xsl:if test="count(child::set) or count(child::group) or count(child::node-ref)">
60			<xsl:message terminate="yes">ERROR: extensible groups with children are currently NOT supported!</xsl:message>
61		</xsl:if>
62		<xsl:apply-templates select="*|@*"/>
63	</xsl:template>
64
65<!-- Localized info elements (desc/label) are not supported currently -->
66	<xsl:template match="info//*[@xml:lang]">
67		<xsl:message terminate="yes">ERROR: Info elements (desc/label) are currently not localized. Remove xml:lang attributes!</xsl:message>
68	</xsl:template>
69
70<!-- check for duplicate child names -->
71	<xsl:template match="@oor:name">
72        <xsl:variable name="item-name" select="."/>
73		<xsl:if test="../following-sibling::*[@oor:name = $item-name]">
74			<xsl:message terminate="yes">ERROR: Duplicate node name '<xsl:value-of select="$item-name"/>'!</xsl:message>
75		</xsl:if>
76	</xsl:template>
77
78<!-- check if properties of type 'any' do not have a value -->
79	<xsl:template match="prop[@oor:type='oor:any']">
80		<xsl:if test="count(value)">
81			<xsl:message terminate="yes">ERROR: Properties of type 'oor:any' MUST NOT have a value!</xsl:message>
82		</xsl:if>
83		<xsl:apply-templates select="*|@*"/>
84	</xsl:template>
85
86<!-- inhibit (explicit) NIL values -->
87	<xsl:template match="value[@xsi:nil]">
88		<xsl:message terminate="yes">ERROR: xsi:nil is not allowed in schemas !</xsl:message>
89	</xsl:template>
90
91<!-- validate for correct node references -->
92	<xsl:template match="@oor:node-type">
93		<xsl:choose>
94			<xsl:when test="../@oor:component">
95				<xsl:variable name ="file">
96					<xsl:call-template name="locateFile"><xsl:with-param name="componentName" select="../@oor:component"/></xsl:call-template>
97				</xsl:variable>
98				<xsl:if test="not(document($file)/oor:component-schema/templates/*[@oor:name=current()])">
99					<xsl:message terminate="yes">ERROR: node-type '<xsl:value-of select="current()"/>' not found!</xsl:message>
100				</xsl:if>
101			</xsl:when>
102			<xsl:when test="not(/oor:component-schema/templates/*[@oor:name=current()])">
103				<xsl:message terminate="yes">ERROR: node-type '<xsl:value-of select="current()"/>' not found!</xsl:message>
104			</xsl:when>
105		</xsl:choose>
106	</xsl:template>
107
108<!-- validate if file name matches component-name -->
109	<xsl:template match="oor:component-schema">
110		<xsl:variable name ="fullName"><xsl:value-of select="@oor:package"/>.<xsl:value-of select="@oor:name"/></xsl:variable>
111		<xsl:if test="$fullName != $componentName">
112			<xsl:message terminate="yes">ERROR: Component name '<xsl:value-of select="$fullName"/>' does not match with file name!</xsl:message>
113		</xsl:if>
114		<xsl:apply-templates select="*|@*"/>
115	</xsl:template>
116
117
118<!-- locate a component file -->
119	<xsl:template name="locateFile">
120		<xsl:param name="componentName"/>
121		<xsl:variable name ="file"><xsl:value-of select="$root"/>/<xsl:value-of select="translate($componentName,'.','/')"/>.xcs</xsl:variable>
122		<xsl:if	test="not( document($file) )">
123			<xsl:message terminate ="yes">**Error: unable to locate document '<xsl:value-of select="translate($componentName,'.','/')"/>.xcd'</xsl:message>
124		</xsl:if>
125		<xsl:value-of select="$file"/>
126	</xsl:template>
127
128</xsl:transform>
129