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

automatic creation of nested elements

Subject: automatic creation of nested elements
From: "Ganesh Babu N" <nbabuganesh@xxxxxxxxx>
Date: Mon, 1 Dec 2008 17:05:17 +0530
 automatic creation of nested elements
Input XML:

   <map>
      <source>bib-reference</source>
      <source>@id</source>
      <target>reference/citation</target>
      <target>@id</target>
   </map>

Required output:
<xsl:template match="bib-reference">
      <xsl:element name="reference">
        <xsl:element name="citation">
         <xsl:attribute name="id">
            <xsl:value-of select="@id"/>
         </xsl:attribute>
         <xsl:apply-templates/>
      </xsl:element>
   <xsl:element>
 </xsl:template>

My XSLT:
<xsl:template match="map">
<xsl:when test="count(child::*) &gt; 3 and not(starts-with(source,'@'))">
				<mac:template match="{source[1]}">
                                   <xsl:variable name="nestedele"
select="tokenize(target[1],'/')"/>
                                      <xsl:for-each select="$nestedele">
                                          <xsl:variable name="tem" select="."/>
                                		<mac:element name="{$tem}">
						<xsl:for-each select="target">
							<xsl:variable name="pos" select="position()"/>
							<xsl:if test="not(position()=1) and exists(../source[2])">
								<mac:attribute name="{substring-after(.,'@')}">
									<mac:value-of select="{../source[$pos]}"/>
								</mac:attribute>
							</xsl:if>							
						</xsl:for-each>
						<mac:apply-templates/>
					</mac:element>
                                   </xsl:for-each>
				</mac:template>
			</xsl:when>
</xsl:template>

This will create one element after the other but it won't create the
nested one. In a result for bib-reference, two elements will be
created with same content. Which is a wrong one. Please guide me how
to generate the nested element structure.

Regards,
Ganesh

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