Link to home
Start Free TrialLog in
Avatar of static86
static86

asked on

How to show data in table?

How can I show data in table with four columns?
<table>
<xsl:for-each select="sth">
<tr>

<td><xsl:value-of select="something"/></td>
</tr>
</xsl:for-each>

Open in new window

Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

I made this source example XML

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <sth>
        <something>A</something>
    </sth>
    <sth>
        <something>Z</something>
    </sth>
    <sth>
        <something>E</something>
    </sth>
    <sth>
        <something>R</something>
    </sth>
    <sth>
        <something>T</something>
    </sth>
    <sth>
        <something>Y</something>
    </sth>
</root>
Try this, the trick is to take each fourth element in the list
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 <xsl:template match="root">
     <table border="1">
         <xsl:for-each select="sth[position() mod 4 = 1]">
             <tr>
                 <xsl:for-each select="self::sth | following-sibling::sth[position() &lt; 4]">
                     <td>
                         <xsl:value-of select="something"/>
                     </td>
                 </xsl:for-each>
             </tr>
         </xsl:for-each>
     </table>
 </xsl:template>
</xsl:stylesheet>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial