top of page

 

 

Commonly used XSLT Elements 

<xsl:stylesheet>

<xsl:template match="xpath expression">

<xsl:value-of select="xpath">

<xsl:attribute>

<xsl:text>

<xsl:for-each select="xpath">

<xsl:if test="condition">

<xsl:choose>

<xsl:when>

<xsl:otherwise>

 

 

Sample XSLT Template

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 

<xsl:template match="/">

  <html>

  <body>

  <h2>My CD Collection</h2>

    <table border="1">

      <tr bgcolor="#9acd32">

        <th style="text-align:left">Title</th>

        <th style="text-align:left">Artist</th>

        <th style="text-align:left">Country</th>

      </tr>

      <xsl:for-each select="catalog/cd">

      <tr>

        <td><xsl:value-of select="title"/></td>

        <td><xsl:value-of select="artist"/></td>

        <td><xsl:value-of select="country"/></td>

      </tr>

      </xsl:for-each>

    </table>

  </body>

  </html>

</xsl:template>

</xsl:stylesheet>

 

Let us use online tool to work on XSLT examples.

 

http://www.xpathtester.com/xslt

 

Let us test the below XML file and the XSLT file.

 

Example1

 

XML File

<?xml version="1.0"?>

<SampleString>

   Welcome to XSLT!

</SimpleString>

 

XSLT File

 

 

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

version="1.0">

<xsl:template match="/SampleString">

<html>

<head>

<title>Hi XSLT!</title>

</head>

<body>

<h1>

<xsl:value-of select="text()"/>

</h1>

</body>

</html>

</xsl:template>

<xsl:value-of select="text()" />

</xsl:stylesheet>

 

Output

 

<html>

<head>

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Hi XSLT!</title>

</head>

<body>

<h1>

   Welcome to XSLT!

</h1>

</body>

</html>

 

 

bottom of page