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

Converting an xml to another xml Using XSLT

Subject: Converting an xml to another xml Using XSLT
From: "Tedla, Sridhar \(LNG-CSP\)" <Sridhar.Tedla@xxxxxxxxxxxxxx>
Date: Tue, 2 May 2006 12:36:19 -0600
converting xml using xslt
Question: Converting an XML markup to another XML Markup Using XSLT.

Sample XML Markup:
<class >
   <classitem>
     <identifier>
        <name>Sales </name>
               <code>1234</code>
     </identifier>
     <classitem>
        <identifier>
          <name> Tax</name>
          <code>5678</code>
       </identifier>
     </classitem>
    </classitem>
</class>

After XSL Transformation, the output markup should be as follows:
  <hier>
          <hierlev >
             <heading>
                <title>Sales</title>
             </heading>
             <hierlev>
                <heading>
                    <title> Tax</title>
                </heading>
               </hierlev>
            </hierlev>
    </hier>

The mapping between Input and output markup elements as follows:

class  -     hier
Classitem - heirlev
identifier -  heading
name       - title
code has no mapping i.e. the element can be ignored in XSLT Code

I have written XSLT code which works for fixed depth of class.Actually I
have written XSLT code for classItem depth of 4, but for simplicity...
the following code is for classItem depth of 2 only.
<xsl:template match="class">
        <xsl:param name="count"/>
        <xsl:param name="v1" select="descendant::name[1]/text()"/>
        <xsl:param name="v2" select="descendant::name[2]/text()"/>
        <xsl:call-template name="createHierLevElement">
          <xsl:with-param name="hierLevContent">
	       <xsl:element name="heading">
	          <xsl:element name="title">
		      <xsl:copy-of select="$v1"/>
	           </xsl:element>
	        </xsl:element>

                <xsl:if test=" $count = 2 ">
		  <xsl:call-template name="createHierLevElement">
                      <xsl:with-param name="hierLevContent">
			  <xsl:element name="heading">
 		             <xsl:element name="title">
                                  <xsl:copy-of select="$v2"/>
			     </xsl:element>
			  </xsl:element>
                       </xsl:with-param>
                   </xsl:call-template>
                </xsl:if>
             </xsl:with-param>
        </xsl:call-template>
  </xsl:template>


  <xsl:template name="createHierLevElement">
      <xsl:param name="hierLevContent" />

        <xsl:element name="hierlev">
           <xsl:copy-of select="$hierLevContent" />
        </xsl:element>
    </xsl:template>

If my input markup has arbitary depth, the above XSLT code will not
work, so I need code which accomodates any depth of ClassItem.



Thanks.
Sridhar

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.