How to format data in a table


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How to format data in a table

Hybrid View

  1. #1
    Anil Guest

    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>


  2. #2
    anil Guest

    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>
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center