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

Child Nodes Problem

Subject: Child Nodes Problem
From: Byomokesh Sahoo <sahoo.byomokesh@xxxxxxxxx>
Date: Thu, 3 Jun 2010 16:16:15 +0530
 Child Nodes Problem
Hi All,

I am trying to convert xml to csv. I am facing problem to get child
node (like ProdIDT, IDV) as one line a tab delimeted txt file. Child
node value is coming close without header. Please look at the below my
input and XSL file.

<Product>
<Record>1616200243</Record>
<Not>03</Not>
<ProductId>
<ProdIDT>02</ProdIDT>
<IDV>1616200243</IDV>
</ProductId>
<ProductId>
<ProdIDT>03</ProdIDT>
<IDV>9781616200244</IDV>
</ProductId>
<ProdFormDe>Electronic book text</ProdFormDe>
<EpTy>000</EpTy>
<NoS/>
<Title>
<TitleT>01</TitleT>
<TTx>The Sound of a Wild Snail Eating</TTx>
<Sbt>A Memoir</Sbt>
</Title>
</Product>

My XSL
======

 <xsl:variable name="delimiter" select="'&#9;'"/>
 <xsl:variable name="fieldNames" select="'yes'"/>

 <xsl:template match="/">

   <xsl:for-each select="//Product/child::*|//Product/self::*">

     <xsl:if test="$fieldNames = 'yes'">

       <xsl:if test="position() = 1 or position()&gt;1">

         <xsl:for-each select="@*">
           <xsl:value-of select="name()"/>

           <xsl:value-of select="$delimiter"/>

         </xsl:for-each>

         <xsl:for-each select="*">
           <xsl:value-of select="name()"/>

           <xsl:if test="position() != last()">
             <xsl:value-of select="$delimiter"/>
           </xsl:if>
         </xsl:for-each>
         <xsl:text>
       </xsl:text>
       </xsl:if>
     </xsl:if>
     <xsl:for-each select="@*">
       <xsl:value-of select="."/>
       <xsl:value-of select="$delimiter"/>
     </xsl:for-each>
     <xsl:for-each select="*">
       <xsl:value-of select="."/>
       <xsl:if test="position() != last()">
         <xsl:value-of select="$delimiter"/>
       </xsl:if>
     </xsl:for-each>
     <xsl:text>
</xsl:text>
   </xsl:for-each>
 </xsl:template>

Required Output
===============

Record          Not     ProductId ProdIDT IDV             ProductId
   ProdIDT IDV             ProdFormDe      EpTy NoS Title
TitleT  TTx     Sbt
1616200243      03                      02      1616200243
         03      9781616200244 Electronic book text            000
        01      The Sound of a Wild Snail Eating        A Memoir



Thanks
Byomokesh

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.