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<xsl:stylesheet
23    version="1.0"
24    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
25    xmlns:rng="http://relaxng.org/ns/structure/1.0"
26    xmlns:xalan="http://xml.apache.org/xalan"
27    exclude-result-prefixes = "xalan"
28    xml:indent="true">
29  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
30
31  <xsl:include href="factorytools.xsl"/>
32
33  <xsl:template match="/">
34    <class>
35      <xsl:for-each select="//rng:define[@name='CT_FFData']">
36	<xsl:call-template name="sprm"/>
37	<xsl:call-template name="attribute"/>
38      </xsl:for-each>
39    </class>
40  </xsl:template>
41
42  <xsl:template name="sprminner">
43    <xsl:variable name="defname" select="@name"/>
44    <xsl:for-each select=".//rng:ref[not(ancestor::rng:element or ancestor::rng:attribute)]">
45      <xsl:call-template name="sprminner"/>
46    </xsl:for-each>
47    <xsl:for-each select=".//rng:element">
48      <xsl:for-each select="rng:ref">
49	<xsl:variable name="refname" select="@name"/>
50	<xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$refname]">
51	  <xsl:call-template name="sprminner"/>
52	</xsl:for-each>
53      </xsl:for-each>
54      <element>
55	<xsl:variable name="elementname" select="@name"/>
56	<xsl:attribute name="name">
57	  <xsl:value-of select="@name"/>
58	</xsl:attribute>
59	<xsl:for-each select="rng:ref">
60	  <xsl:variable name="refname" select="@name"/>
61	  <xsl:for-each select="ancestor::namespace/resource[@name=$refname]">
62	    <xsl:attribute name="action">
63	      <xsl:choose>
64		<xsl:when test="@resource='Properties'">
65		  <xsl:text>resolve</xsl:text>
66		</xsl:when>
67		<xsl:otherwise>
68		  <xsl:text>set</xsl:text>
69		</xsl:otherwise>
70	      </xsl:choose>
71	    </xsl:attribute>
72	  </xsl:for-each>
73	  <xsl:for-each select="ancestor::namespace/resource[@name=$defname]">
74	    <xsl:for-each select="element[@name=$elementname]">
75	      <xsl:attribute name="id">
76		<xsl:call-template name="idtoqname">
77		  <xsl:with-param name="id">
78		    <xsl:value-of select="@tokenid"/>
79		  </xsl:with-param>
80		</xsl:call-template>
81	      </xsl:attribute>
82	    </xsl:for-each>
83	  </xsl:for-each>
84	</xsl:for-each>
85      </element>
86    </xsl:for-each>
87  </xsl:template>
88
89  <xsl:template name="sprm">
90    <sprm>
91      <xsl:call-template name="sprminner"/>
92    </sprm>
93  </xsl:template>
94
95  <xsl:template name="attributeinner">
96    <xsl:param name="parent"/>
97    <xsl:for-each select=".//rng:ref[not(ancestor::rng:element or ancestor::rng:attribute)]">
98      <xsl:variable name="refname" select="@name"/>
99      <xsl:comment><xsl:value-of select="$newparent"/></xsl:comment>
100      <xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$refname]">
101	<xsl:call-template name="attributeinner">
102	  <xsl:with-param name="parent" select="$parent"/>
103	</xsl:call-template>
104      </xsl:for-each>
105    </xsl:for-each>
106    <xsl:for-each select=".//rng:element">
107      <xsl:variable name="newparent">
108	<xsl:if test="string-length($parent)">
109	  <xsl:value-of select="$parent"/>
110	  <xsl:text>:</xsl:text>
111	</xsl:if>
112	<xsl:value-of select="@name"/>
113      </xsl:variable>
114      <xsl:for-each select="rng:ref">
115	<xsl:variable name="refname" select="@name"/>
116	<xsl:for-each select="ancestor::namespace/rng:grammar/rng:define[@name=$refname]">
117	  <xsl:call-template name="attributeinner">
118	    <xsl:with-param name="parent" select="$newparent"/>
119	  </xsl:call-template>
120	</xsl:for-each>
121      </xsl:for-each>
122    </xsl:for-each>
123    <xsl:variable name="defname" select="@name"/>
124    <xsl:variable name="resource">
125      <xsl:for-each select="ancestor::namespace/resource[@name=$defname]">
126	<xsl:value-of select="@resource"/>
127      </xsl:for-each>
128    </xsl:variable>
129    <xsl:if test="$resource='Properties'">
130      <xsl:for-each select=".//rng:attribute">
131	<xsl:variable name="attrname" select="@name"/>
132	<attribute>
133	  <xsl:attribute name="name">
134	    <xsl:if test="string-length($parent) > 0">
135	      <xsl:value-of select="$parent"/>
136	      <xsl:text>:</xsl:text>
137	    </xsl:if>
138	    <xsl:value-of select="$attrname"/>
139	  </xsl:attribute>
140	  <xsl:for-each select="ancestor::namespace/resource[@name=$defname]">
141	    <xsl:for-each select="attribute[@name=$attrname]">
142	      <xsl:attribute name="id">
143		<xsl:call-template name="idtoqname">
144		  <xsl:with-param name="id">
145		    <xsl:value-of select="@tokenid"/>
146		  </xsl:with-param>
147		</xsl:call-template>
148	      </xsl:attribute>
149	    </xsl:for-each>
150	  </xsl:for-each>
151	</attribute>
152      </xsl:for-each>
153    </xsl:if>
154  </xsl:template>
155
156  <xsl:template name="attribute">
157    <attribute>
158      <xsl:call-template name="attributeinner"/>
159    </attribute>
160  </xsl:template>
161
162</xsl:stylesheet>