1<?xml version="1.0" encoding="UTF-8"?>
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<xsl:stylesheet version="1.0"
24	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
25	xmlns:rng="http://relaxng.org/ns/structure/1.0">
26
27<xsl:include href="factorytools.xsl"/>
28<xsl:output method="xml"/>
29
30<xsl:template match="/">
31	<analyze>
32		<xsl:for-each select="/model/namespace[not(@todo='ignore')]">
33			<xsl:call-template name="analyzegrammar"/>
34		</xsl:for-each>
35	</analyze>
36</xsl:template>
37
38<xsl:template name="analyzegrammar">
39	<xsl:variable name="nsname" select="@name"/>
40	<xsl:for-each select="rng:grammar/rng:define">
41		<xsl:variable name="defname" select="@name"/>
42		<xsl:for-each select=".//rng:attribute|.//rng:element">
43			<xsl:choose>
44				<xsl:when test="local-name()='element'">
45					<element>
46						<xsl:call-template name="defineattrs">
47							<xsl:with-param name="nsname" select="$nsname"/>
48							<xsl:with-param name="defname" select="$defname"/>
49						</xsl:call-template>
50					</element>
51				</xsl:when>
52				<xsl:when test="local-name()='attribute'">
53					<attribute>
54						<xsl:call-template name="defineattrs">
55							<xsl:with-param name="nsname" select="$nsname"/>
56							<xsl:with-param name="defname" select="$defname"/>
57						</xsl:call-template>
58					</attribute>
59				</xsl:when>
60			</xsl:choose>
61		</xsl:for-each>
62	</xsl:for-each>
63</xsl:template>
64
65<xsl:template name="defineattrs">
66	<xsl:param name="nsname"/>
67	<xsl:param name="defname"/>
68
69	<xsl:variable name="localname" select="local-name()"/>
70	<xsl:variable name="name" select="@name"/>
71
72	<xsl:attribute name="id">
73		<xsl:value-of select="$nsname"/>
74		<xsl:text>:</xsl:text>
75		<xsl:value-of select="$defname"/>
76		<xsl:text>:</xsl:text>
77		<xsl:value-of select="@name"/>
78	</xsl:attribute>
79	<xsl:for-each select="ancestor::namespace/resource[@name=$defname]">
80		<xsl:attribute name="resource"><xsl:value-of select="@resource"/></xsl:attribute>
81		<xsl:choose>
82			<xsl:when test="$localname='attribute'">
83				<xsl:for-each select="attribute[@name=$name and @tokenid]">
84					<xsl:attribute name="tokenid"><xsl:value-of select="@tokenid"/></xsl:attribute>
85					<xsl:attribute name="qname">
86						<xsl:call-template name="idtoqname">
87							<xsl:with-param name="id" select="@tokenid"/>
88						</xsl:call-template>
89					</xsl:attribute>
90                    <xsl:attribute name="namespace">
91                        <xsl:value-of select="$nsname"/>
92                    </xsl:attribute>
93                    <xsl:attribute name="define">
94                        <xsl:value-of select="$defname"/>
95                    </xsl:attribute>
96                    <xsl:attribute name="name">
97                        <xsl:value-of select="@name"/>
98                    </xsl:attribute>
99				</xsl:for-each>
100			</xsl:when>
101			<xsl:when test="$localname='element'">
102				<xsl:for-each select="element[@name=$name and @tokenid]">
103					<xsl:attribute name="tokenid"><xsl:value-of select="@tokenid"/></xsl:attribute>
104					<xsl:attribute name="qname">
105						<xsl:call-template name="idtoqname">
106							<xsl:with-param name="id" select="@tokenid"/>
107						</xsl:call-template>
108					</xsl:attribute>
109                    <xsl:attribute name="namespace">
110                        <xsl:value-of select="$nsname"/>
111                    </xsl:attribute>
112                    <xsl:attribute name="define">
113                        <xsl:value-of select="$defname"/>
114                    </xsl:attribute>
115                    <xsl:attribute name="name">
116                        <xsl:value-of select="@name"/>
117                    </xsl:attribute>
118				</xsl:for-each>
119			</xsl:when>
120		</xsl:choose>
121        <xsl:copy-of select="@tag"/>
122	</xsl:for-each>
123</xsl:template>
124</xsl:stylesheet>