I'm trying to reverse-engineer a schema into a model. As i'm new in XSLT
(especially templates) i have some problem with recursive behaviour of
templates.
the schema (inlining) i'm working on is (in DTD to understand):
----------------------------------------------------------------------
<!ELEMENT BookStore (Book+)>
<!ELEMENT Book (Title, Author, Date, ISBN, Publisher)>
<!ELEMENT publisher(Name,Address)>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Date (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Address (#PCDATA)>
----------------------------------------------------
My goal is to extract (from the schema corresponding to DTD above)some
information:
1. Any element containing other element is transformed to a class
2. Simple elements within a class are transformed to attributes
which have to give this:
----------------------------------------------------
<model>
<class name="BookStore" id="1"/>
<class name="Book" id="2">
<attribute id="3"name="Title"/>
<attribute id="4" name="Author"/>
<attribute id="5"name="Date"/>
<attribute id="6"name="ISBN"/>
</class>
<class name="Publisher">
<attribute id="7" name="Name"/>
<attribute id="8" name="Address"/>
</class>
</model>
----------------------------------------------------
Please tell me what's wrong with my xslt program.
N.B. both my xslt program and the bookstore schema are enclosed with this
message.
Thanks
-------------------------------------------------------------
Here's my schema : bookstore.xsd
-------------------------------------------------------------
<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org" xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Title" type="xsd:string" />
<xsd:element name="Author" type="xsd:string" />
<xsd:element name="Date" type="xsd:string" />
<xsd:element name="ISBN" type="xsd:string" />
<xsd:element name="Publisher">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="address" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
-------------------------------------------------------------
Here's my program : program.xsl
-------------------------------------------------------------
<?xml version="1.0"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsl:output indent="yes" method="xml" encoding="iso-8859-1"/>
<!--"""""""""""""""""""""""""""""""""""""""""""""-->
<xsl:template match="/">
<Model>
<xsl:apply-templates/>
</Model>
</xsl:template>
<!--"""""""""""""""""""""""""""""""""""""""""""""-->
<xsl:template match="xsd:schema">
<xsl:apply-templates/>
</xsl:template>
<!--"""""""""""""""""""""""""""""""""""""""""""""-->
<xsl:template match="xsd:element">
<class>
<xsl:attribute name="id"><xsl:value-of
select="generate-id(.)"/></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:call-template name="Attributes"/>
</class>
</xsl:template>
<!--"""""""""""""""""""""""""""""""""""""""""""""-->
<xsl:template name="Attributes">
<xsl:for-each select="./././xsd:element[(_at_)type]">
<attribute>
<xsl:attribute name="id"><xsl:value-of
select="generate-id(.)"/></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute
</attribute>
</xsl:for-each>
</xsl:template>
</xsl:transform>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list