Friday, April 27, 2012

Quick look at XSLT (XSL Transformations)

What is XSLT?
XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents.
The XSLT language was defined by the World Wide Web Consortium (W3C), and version 1.0 of the language was published as a Recommendation on November 16, 1999.

How to transform XML into XHTML using XSLT.

Save the following content in score.xsl.

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

<xsl:stylesheet version="1.0"

<xsl:template match="/">
  <h2>Score card</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
    <xsl:for-each select="card/cd">
      <td><xsl:value-of select="player"/></td>
      <td><xsl:value-of select="score"/></td>


Save the following content in score.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="score.xsl"?>
<!-- Edited by XMLSpy® -->
<country>Sri Lanka</country>

When you run it in browser you will get the following output.

Score card

Player Score
Sanath 400
Sachin 100
Afriddi 400

Some important links

What kind of language is XSLT?

XSLT tutorial

No comments:

Post a Comment