merge the formfield patch from ooo-build
[ooovba.git] / writerfilter / source / ooxml / checkmodel.xsl
blob9768bb5ebfc3df202f0e37971702146b59ed5c5f
1 <!--
2 /*************************************************************************
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 Copyright 2008 by Sun Microsystems, Inc.
8 OpenOffice.org - a multi-platform office productivity suite
10 $RCSfile: checkmodel.xsl,v $
12 $Revision: 1.3 $
14 This file is part of OpenOffice.org.
16 OpenOffice.org is free software: you can redistribute it and/or modify
17 it under the terms of the GNU Lesser General Public License version 3
18 only, as published by the Free Software Foundation.
20 OpenOffice.org is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU Lesser General Public License version 3 for more details
24 (a copy is included in the LICENSE file that accompanied this code).
26 You should have received a copy of the GNU Lesser General Public License
27 version 3 along with OpenOffice.org. If not, see
28 <http://www.openoffice.org/license.html>
29 for a copy of the LGPLv3 License.
31 ************************************************************************/
33 -->
34 <xsl:stylesheet
35 version="1.0"
36 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
37 xmlns:rng="http://relaxng.org/ns/structure/1.0"
38 xml:space="default" xml:indent="true">
39 <xsl:output method="text" />
42 <xsl:template name="noannotation">
43 <xsl:for-each select="//namespace">
44 <xsl:variable name="nsname" select="@name"/>
45 <xsl:value-of select="./rng:grammar/@ns"/>
46 <xsl:text>&#xa;</xsl:text>
47 <xsl:for-each select=".//rng:define">
48 <xsl:variable name="name" select="@name"/>
49 <xsl:if test="not(ancestor::namespace//resource[@name=$name])">
50 <xsl:text>noannotation: </xsl:text>
51 <xsl:value-of select="$nsname"/>
52 <xsl:text>::</xsl:text>
53 <xsl:value-of select="$name"/>
54 <xsl:text>&#xa;</xsl:text>
55 </xsl:if>
56 </xsl:for-each>
57 </xsl:for-each>
58 </xsl:template>
60 <xsl:template name="checkmodel">
61 <xsl:for-each select="//namespace">
62 <xsl:variable name="nsname" select="@name"/>
63 <xsl:for-each select=".//rng:define">
64 <xsl:call-template name="orphanedprops"/>
65 <xsl:variable name="definename" select="@name"/>
66 <xsl:if test="not(ancestor::namespace//resource[@name=$definename])">
67 <xsl:text>no annotation: </xsl:text>
68 <xsl:value-of select="$nsname"/>
69 <xsl:text>::</xsl:text>
70 <xsl:value-of select="$definename"/>
71 <xsl:text>&#xa;</xsl:text>
72 </xsl:if>
73 <xsl:for-each select=".//rng:element">
74 <xsl:variable name="elementname" select="@name"/>
75 <xsl:for-each select="ancestor::namespace//resource[@name=$definename and @resource='Properties']">
76 <xsl:if test="not(.//element[@name=$elementname])">
77 <xsl:text>missing element: </xsl:text>
78 <xsl:value-of select="$nsname"/>
79 <xsl:text>::</xsl:text>
80 <xsl:value-of select="$definename"/>
81 <xsl:text>::</xsl:text>
82 <xsl:value-of select="$elementname"/>
83 <xsl:text>&#xa;</xsl:text>
84 </xsl:if>
85 <xsl:call-template name="orphanedprops"/>
86 </xsl:for-each>
87 </xsl:for-each>
88 <xsl:for-each select=".//rng:attribute">
89 <xsl:variable name="attributename" select="@name"/>
90 <xsl:for-each select="ancestor::namespace//resource[@name=$definename and @resource='Properties']">
91 <xsl:if test="not(.//attribute[@name=$attributename])">
92 <xsl:text>missing attribute: </xsl:text>
93 <xsl:value-of select="$nsname"/>
94 <xsl:text>::</xsl:text>
95 <xsl:value-of select="$definename"/>
96 <xsl:text>::</xsl:text>
97 <xsl:value-of select="$attributename"/>
98 <xsl:text>&#xa;</xsl:text>
99 </xsl:if>
100 <xsl:call-template name="orphanedprops"/>
101 </xsl:for-each>
102 </xsl:for-each>
103 </xsl:for-each>
104 </xsl:for-each>
105 </xsl:template>
107 <xsl:key name="defines-with-name" match="rng:define" use="@name"/>
109 <xsl:template name="defineforref">
110 <xsl:variable name="grammarid" select="generate-id(ancestor::grammar)"/>
111 <xsl:variable name="defineingrammar" select="key('defines-with-name', @name)[generate-id(ancestor::grammar) = $grammarid]"/>
112 <xsl:choose>
113 <xsl:when test="$defineingrammar">
114 <xsl:value-of select="$defineingrammar"/>
115 </xsl:when>
116 <xsl:otherwise>
117 <xsl:value-of select="key('defines-with-name', @name)"/>
118 </xsl:otherwise>
119 </xsl:choose>
120 </xsl:template>
122 <xsl:template name="contextresource">
123 <xsl:variable name="name" select="@name"/>
124 <xsl:value-of select="ancestor::namespace//resource[@name=$name]/@resource"/>
125 </xsl:template>
127 <xsl:template name="orphanedprops">
128 <xsl:variable name="nsname" select="ancestor::namespace/@name"/>
129 <xsl:for-each select=".//rng:ref[not (ancestor::rng:element or ancestor::rng:attribute)]">
130 <xsl:variable name="defineresource">
131 <xsl:for-each select="ancestor::rng:define">
132 <xsl:call-template name="contextresource"/>
133 </xsl:for-each>
134 </xsl:variable>
135 <xsl:variable name="definename" select="ancestor::rng:define/@name"/>
136 <xsl:variable name="mydefine">
137 <xsl:copy>
138 <xsl:call-template name="defineforref"/>
139 </xsl:copy>
140 </xsl:variable>
141 <xsl:variable name="myresource">
142 <xsl:call-template name="contextresource"/>
143 </xsl:variable>
144 <xsl:if test="$myresource = 'Properties'">
145 <xsl:choose>
146 <xsl:when test="$defineresource = 'Properties'"/>
147 <xsl:when test="$defineresource = 'Stream'"/>
148 <xsl:otherwise>
149 <xsl:text>orphaned properties: </xsl:text>
150 <xsl:value-of select="$nsname"/>
151 <xsl:text>:</xsl:text>
152 <xsl:value-of select="$definename"/>
153 <xsl:text>(</xsl:text>
154 <xsl:value-of select="$defineresource"/>
155 <xsl:text>)-&gt;</xsl:text>
156 <xsl:value-of select="@name"/>
157 <xsl:text>(</xsl:text>
158 <xsl:value-of select="$myresource"/>
159 <xsl:text>)&#xa;</xsl:text>
160 </xsl:otherwise>
161 </xsl:choose>
162 </xsl:if>
163 </xsl:for-each>
164 </xsl:template>
166 <xsl:template match="/">
167 <out>
168 <xsl:call-template name="checkmodel"/>
169 </out>
170 </xsl:template>
171 </xsl:stylesheet>