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