Software Technology Tips

How to Create a Tablular Structure of a XML File Using XSL.
Sometimes we need to display the data that are present in a xml file in a tabular format. Following code explan how to display a tabular format of the XML file by applying XSL stylesheet.
XML-FILE

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="showtableformat.xsl"?>
<StudentInfo>
  <Students>
    <FirstName>Monali</FirstName>
    <LastName> Nayak </LastName>
  </Students>
  <Students>
    <FirstName>Sarita</FirstName>
    <LastName> Dash </LastName>
  </Students>
  <Students>
   <FirstName>Asrita</FirstName>
   <LastName> Pandit </LastName>
  </Students>
</StudentInfo>

XSL-FILE(showtableformat.xsl)
 
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <html>
      <head>
        <title>Student Information</title>
      </head>
    <body>
      <xsl:apply-templates/>
    </body>
    </html>
</xsl:template>
  <xsl:template match = "StudentInfo">
    <table width="400" border="1" align ="center" >
      <tr bgcolor ="598744">
        <th>First Name</th>
        <th>Last Name</th>
      </tr>
      <xsl:for-each select="Students" >
        <tr>
          <td>
            <xsl:value-of select="FirstName" />
          </td>
          <td>
            <xsl:value-of select="LastName" />
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>


Related Tags:

XML

Author: Surama Hotta

XML

Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

This site uses cookies. We respect your privacy.copyright (c) Mindfire Solutions 2007-2015. Login