Monday, 15 July 2013

XSLT - Basic samples Part-1

          XSLT is the abbreviation of Extensible Stylesheet Language Transformation.It is the Stylesheet language for XML.Template is applied for every node in xml.

Tags present in XSLT are <template>,  <value-of>,  <for-each>, <if>, <choose>

template 
  template is a tag which will apply the rules for the node , for which it has written

XML

<Employees>
   <Employee>
        <Name>Rajesh</Name>
        <Age>23</Age>
   </Employee>
   <Employee>
        <Name>Suresh</Name>
        <Age>21</Age>
   </Employee>
   <Employee>
        <Name>Praba</Name>
        <Age>28</Age>
   </Employee>
</Employees>

XSLT
<xsl:stylesheet version="1.0" >
<xsl:template match="/">
     <html>
        <body>
         <table border="2">
              <tr><th colspan="2">Employee List</th></tr>
              <tr bgcolor="gray"><th>Name</th><th>Age</th></tr>
               <xsl:for-each select="Employees/Employee">
                <tr>
               <td><xsl:value-of select="Name"/></td>
               <td><xsl:value-of select="Age"/></td>  
               </tr>
            </xsl:for-each>
         </table>
        </body>
     </html>

</xsl:template>
</xsl:stylesheet >

Output