Bump version to 4.3-4
[LibreOffice.git] / writerfilter / source / ooxml / checkmodel.xsl
blob4dd133fb7eae7afea4cfb6712ca63c8d6ed091ef
1 <!--
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 -->
19 <xsl:stylesheet
20 version="1.0"
21 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22 xmlns:rng="http://relaxng.org/ns/structure/1.0"
23 xml:space="default" xml:indent="true">
24 <xsl:output method="text" />
26 <xsl:template name="noannotation">
27 <xsl:for-each select="//namespace">
28 <xsl:variable name="nsname" select="@name"/>
29 <xsl:value-of select="./rng:grammar/@ns"/>
30 <xsl:text>&#xa;</xsl:text>
31 <xsl:for-each select=".//rng:define">
32 <xsl:variable name="name" select="@name"/>
33 <xsl:if test="not(ancestor::namespace//resource[@name=$name])">
34 <xsl:text>noannotation: </xsl:text>
35 <xsl:value-of select="$nsname"/>
36 <xsl:text>::</xsl:text>
37 <xsl:value-of select="$name"/>
38 <xsl:text>&#xa;</xsl:text>
39 </xsl:if>
40 </xsl:for-each>
41 </xsl:for-each>
42 </xsl:template>
44 <xsl:template name="checkmodel">
45 <xsl:for-each select="//namespace">
46 <xsl:variable name="nsname" select="@name"/>
47 <xsl:for-each select=".//rng:define">
48 <xsl:call-template name="orphanedprops"/>
49 <xsl:variable name="definename" select="@name"/>
50 <xsl:if test="not(ancestor::namespace//resource[@name=$definename])">
51 <xsl:text>no annotation: </xsl:text>
52 <xsl:value-of select="$nsname"/>
53 <xsl:text>::</xsl:text>
54 <xsl:value-of select="$definename"/>
55 <xsl:text>&#xa;</xsl:text>
56 </xsl:if>
57 <xsl:for-each select=".//rng:element">
58 <xsl:variable name="elementname" select="@name"/>
59 <xsl:for-each select="ancestor::namespace//resource[@name=$definename and @resource='Properties']">
60 <xsl:if test="not(.//element[@name=$elementname])">
61 <xsl:text>missing element: </xsl:text>
62 <xsl:value-of select="$nsname"/>
63 <xsl:text>::</xsl:text>
64 <xsl:value-of select="$definename"/>
65 <xsl:text>::</xsl:text>
66 <xsl:value-of select="$elementname"/>
67 <xsl:text>&#xa;</xsl:text>
68 </xsl:if>
69 <xsl:call-template name="orphanedprops"/>
70 </xsl:for-each>
71 </xsl:for-each>
72 <xsl:for-each select=".//rng:attribute">
73 <xsl:variable name="attributename" select="@name"/>
74 <xsl:for-each select="ancestor::namespace//resource[@name=$definename and @resource='Properties']">
75 <xsl:if test="not(.//attribute[@name=$attributename])">
76 <xsl:text>missing attribute: </xsl:text>
77 <xsl:value-of select="$nsname"/>
78 <xsl:text>::</xsl:text>
79 <xsl:value-of select="$definename"/>
80 <xsl:text>::</xsl:text>
81 <xsl:value-of select="$attributename"/>
82 <xsl:text>&#xa;</xsl:text>
83 </xsl:if>
84 <xsl:call-template name="orphanedprops"/>
85 </xsl:for-each>
86 </xsl:for-each>
87 </xsl:for-each>
88 </xsl:for-each>
89 </xsl:template>
91 <xsl:key name="defines-with-name" match="rng:define" use="@name"/>
93 <xsl:template name="defineforref">
94 <xsl:variable name="grammarid" select="generate-id(ancestor::grammar)"/>
95 <xsl:variable name="defineingrammar" select="key('defines-with-name', @name)[generate-id(ancestor::grammar) = $grammarid]"/>
96 <xsl:choose>
97 <xsl:when test="$defineingrammar">
98 <xsl:value-of select="$defineingrammar"/>
99 </xsl:when>
100 <xsl:otherwise>
101 <xsl:value-of select="key('defines-with-name', @name)"/>
102 </xsl:otherwise>
103 </xsl:choose>
104 </xsl:template>
106 <xsl:template name="contextresource">
107 <xsl:variable name="name" select="@name"/>
108 <xsl:value-of select="ancestor::namespace//resource[@name=$name]/@resource"/>
109 </xsl:template>
111 <xsl:template name="orphanedprops">
112 <xsl:variable name="nsname" select="ancestor::namespace/@name"/>
113 <xsl:for-each select=".//rng:ref[not (ancestor::rng:element or ancestor::rng:attribute)]">
114 <xsl:variable name="defineresource">
115 <xsl:for-each select="ancestor::rng:define">
116 <xsl:call-template name="contextresource"/>
117 </xsl:for-each>
118 </xsl:variable>
119 <xsl:variable name="definename" select="ancestor::rng:define/@name"/>
120 <xsl:variable name="mydefine">
121 <xsl:copy>
122 <xsl:call-template name="defineforref"/>
123 </xsl:copy>
124 </xsl:variable>
125 <xsl:variable name="myresource">
126 <xsl:call-template name="contextresource"/>
127 </xsl:variable>
128 <xsl:if test="$myresource = 'Properties'">
129 <xsl:choose>
130 <xsl:when test="$defineresource = 'Properties'"/>
131 <xsl:when test="$defineresource = 'Stream'"/>
132 <xsl:otherwise>
133 <xsl:text>orphaned properties: </xsl:text>
134 <xsl:value-of select="$nsname"/>
135 <xsl:text>:</xsl:text>
136 <xsl:value-of select="$definename"/>
137 <xsl:text>(</xsl:text>
138 <xsl:value-of select="$defineresource"/>
139 <xsl:text>)-&gt;</xsl:text>
140 <xsl:value-of select="@name"/>
141 <xsl:text>(</xsl:text>
142 <xsl:value-of select="$myresource"/>
143 <xsl:text>)&#xa;</xsl:text>
144 </xsl:otherwise>
145 </xsl:choose>
146 </xsl:if>
147 </xsl:for-each>
148 </xsl:template>
150 <xsl:template match="/">
151 <out>
152 <xsl:call-template name="checkmodel"/>
153 </out>
154 </xsl:template>
155 </xsl:stylesheet>