How to format data in a table
I have few items in xml. The number of items can change. I want to display
these items in a table format, how can I do using XSLT?
Ex:
<subroutine>
<script id="1">
<name>test</name>
</script>
<script id="2">
<name>test2</name>
</script>
<script id="3">
<name>test3</name>
</script>
<script id="4">
<name>test4</name>
</script>
<script id="5">
<name>test5</name>
</script>
</subroutine>
I want to display above as
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td></td>
</tr>
</table>
Any suggestions how to do it.
My thought process on how to do is below but I am stuck and don't have any
clue what to do next
<xsl:template match="subroutine">
<div id="Subroutines">
<H2 align="center">Avenue Scripts</H2>
<table border="1">
<xsl:for-each select="script">
<xsl:if test="position() mod 4 = 1">
<tr>
<xsl:call-template name="srtd"/>
</tr>
</xsl:if>
</xsl:for-each>
</table>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template name="srtd">
<td>
<xsl:value-of select="@id"/>
</td>
<td>
<xsl:value-of select="@id"/>
</td>
<td>
<xsl:value-of select="@id"/>
</td>
<td>
<xsl:value-of select="@id"/>
</td>
</xsl:template>
Re: How to format data in a table
Anybody?
"Anil" <abatra@tidemark.com> wrote:
>
>I have few items in xml. The number of items can change. I want to display
>these items in a table format, how can I do using XSLT?
>Ex:
><subroutine>
><script id="1">
><name>test</name>
></script>
><script id="2">
><name>test2</name>
></script>
><script id="3">
><name>test3</name>
></script>
><script id="4">
><name>test4</name>
></script>
><script id="5">
><name>test5</name>
></script>
></subroutine>
>
>
>I want to display above as
>
><table>
> <tr>
> <td>1</td>
> <td>2</td>
> <td>3</td>
> </tr>
> <tr>
> <td>4</td>
> <td>5</td>
> <td></td>
> </tr>
>
></table>
>
>Any suggestions how to do it.
>
>
>My thought process on how to do is below but I am stuck and don't have any
>clue what to do next
>
><xsl:template match="subroutine">
> <div id="Subroutines">
> <H2 align="center">Avenue Scripts</H2>
><table border="1">
>
> <xsl:for-each select="script">
>
>
> <xsl:if test="position() mod 4 = 1">
> <tr>
> <xsl:call-template name="srtd"/>
> </tr>
> </xsl:if>
> </xsl:for-each>
>
> </table>
>
> <xsl:apply-templates/>
> </div>
> </xsl:template>
>
> <xsl:template name="srtd">
> <td>
> <xsl:value-of select="@id"/>
> </td>
> <td>
> <xsl:value-of select="@id"/>
> </td>
>
> <td>
> <xsl:value-of select="@id"/>
> </td>
>
> <td>
> <xsl:value-of select="@id"/>
> </td>
>
> </xsl:template>
>