[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Inserting leaf node names as headers in a table


Subject: [xsl] Inserting leaf node names as headers in a table
From: Hemanth Singamsetty <hemanth.singamsetty@xxxxxxxxx>
Date: Mon, 13 Sep 2004 18:53:42 -0700

> I'm trying to insert the leaf node tagnames, of a XML file, as header values in a table using XSLT.
> My XML file looks like this:
>
> <A>
>    <B>
>       <D>
>         <E>
>           <E1>e1</E1>
>           <E2>e2</E2>
>           <E3>e3</E3>
>             :
>          </E>
>         <F>
>           <F1>f1</F1>
>           <F2>f2</F2>
>           <F3>f3</F3>
>             :
>         </F>
>         <G>
>           <GG>
>             <GGG>ggg1</GGG>
>             <GGG>ggg2</GGG>
>           </GG>
>           <GG>
>             <GGG>ggg3<GGG>
>             <GGG>ggg4</GGG>
>           </GG>
>             :
>             :
>         </G>
>       </D>
>       <D>
>       <D>
>          :
>          :
>    <B>
>    <B>
>      :
>      :
> </A>
>
>
> The output I'm trying to get is a table with different columns having headers as
> (E1, E2, E3....,F1, F2, F3,...., GGG1, GGG2, GGG3, GGG4....) and the values inside
> the table corresponding to the above header as
> (e1, e2, e3,....,f1, f2, f3....ggg1, ggg2, ggg3, ggg4...and so on for each <D>)
>
>
> I was able to create and populate the table with values using <xsl: apply-templates> but
> I'm new to XML and XSL programming and I'm finding it difficult to display the header values
> only once, i mean, i'm trying to put a <xsl:if> condition in a <xsl:for-each> to stop after
> one iteration.
>
> I'm doing something like this in the <xsl:template match="B">, but it didn't work.
>
> <tr>
> <xsl:for-each select="????">
>    <xsl:if test="position() &lt; count("????")">
>       <th><xsl:value-of select="local-name()"/></th>
>    </xsl:if>
> </xsl:for-each>
> </tr>
>
>
> Hope my question is clear. Can someone help me figure out how should I do this?
>
>
>
> Thanks in advance,
> Hemanth


Current Thread
Keywords