[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

problem with templates

Subject: problem with templates
From: "belangour abdessamad" <abdessamad.belangour@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 15 Oct 2003 17:10:26 +0200
xsl attribute id
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[@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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.