2. • XSL stands for EXtensible Stylesheet
Language, and is a style sheet language
for XML documents.
• XSLT stands for XSL Transformations.
3. What is XSL?
• XSL is the style sheet language for XML
• Style sheets are typically used to specify
how information should be displayed.
• They lead to separation of document's
content from presentational information.
4. XSL Languages
XSL consists of three parts:
• XSLT is a language for transforming
XML documents
• XPath is a language for defining parts of
an XML document
• XSL-FO is a language for formatting XML
documents
5. What is XSLT?
• XSLT is the most important part of XSL
• XSLT transforms an XML document
into another XML document
• XSLT uses XPath to navigate in XML
documents
• XSLT is a W3C Recommendation
6. History
• XSL is derived from DSSSL
– Document Style and Semantics Specification
Language
• The style sheet language for SGML
• Based on the Scheme (Lisp) programming language
– XSL uses XML syntax instead of Scheme
8. How does XSL work?
• The XSL processor parses the source
XML document
• Templates in the stylesheet are matched
against patterns in the source document
• The templates are expanded, producing
fragments of the target document
• This process is (typically) applied
recursively until all pattern-matches have
been exhausted
• The complete target document is
produced as output
9. XSLT - Transformation
• Correct Style Sheet Declaration
• The root element that declares the
document to be an XSL style sheet is
<xsl:stylesheet> or <xsl:transform>.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Or
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
12. Link the XSL Style Sheet to the XML
Document
• Add the XSL style sheet reference to your XML
document ("cdcatalog.xml"):
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
.
.
</catalog> View the result
13. 1. XSLT <xsl:template> Element
• An XSL style sheet consists of one or
more set of rules that are called
templates.
• A template contains rules to apply when a
specified node is matched.
14. The <xsl:template> Element
• The <xsl:template> element is used to
build templates.
• The match attribute is used to associate a
template with an XML element.
• The match attribute can also be used to
define a template for the entire XML
document.
• The value of the match attribute is an
XPath expression (i.e. match="/" defines
the whole document).
20. 3. XSLT <xsl:for-each> Element
• The <xsl:for-each> element allows you to
do looping in XSLT.
• The XSL <xsl:for-each> element can be
used to select every XML element of a
specified node-set:
30. 5. XSLT <xsl:if> Element
• The <xsl:if> element is used to put a conditional
test against the content of the XML file.
• To put a conditional if test against the content of
the XML file, add an <xsl:if> element to the XSL
document.
• Syntax
<xsl:if test="expression">
...some output if the expression is true...
</xsl:if>
31. Where to Put the <xsl:if> Element
<?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>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:if test="price > 10">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
34. 6. XSLT <xsl:choose> Element
• The <xsl:choose> element is used in
conjunction with <xsl:when> and
<xsl:otherwise> to express multiple
conditional tests.
36. Where to put the Choose Condition
• To insert a multiple conditional test against
the XML file, add the <xsl:choose>,
<xsl:when>, and <xsl:otherwise> elements
to the XSL file:
38. • The code above will add a pink background-
color to the "Artist" column WHEN the price
of the CD is higher than 10.
1cdcatalog.xml XSL:choose.xsl
View the result