Skip to content Skip to sidebar Skip to footer

Use Xslt To Convert Xml List Into Html Table With Multiple Columns

Say I have an xml document consisting of a list as shown below: First Item Second Item Third Item&

Solution 1:

Try this:

<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/Items">
    <table>
      <xsl:for-each select="Item[position() mod 2 = 1]">
        <xsl:variable name="pos" select="position() - 1" />
        <tr>
          <td><xsl:value-of select="."/></td>
          <td><xsl:value-of select="//Item[position() = ($pos * 2) + 2]"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

Post a Comment for "Use Xslt To Convert Xml List Into Html Table With Multiple Columns"