0% found this document useful (0 votes)
53 views9 pages

XML and XSLT

XSLT is a language used to transform XML documents into other formats like HTML. It uses templates with elements like <xsl:template> that can match elements in an XML file. Other elements like <xsl:value-of> extract the value of an XML element and add it to the output. <xsl:for-each> selects every element of a specified node-set, and can filter the output using criteria in its select attribute. <xsl:sort> adds sorting capability when used inside <xsl:for-each>.

Uploaded by

Ryu Villota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views9 pages

XML and XSLT

XSLT is a language used to transform XML documents into other formats like HTML. It uses templates with elements like <xsl:template> that can match elements in an XML file. Other elements like <xsl:value-of> extract the value of an XML element and add it to the output. <xsl:for-each> selects every element of a specified node-set, and can filter the output using criteria in its select attribute. <xsl:sort> adds sorting capability when used inside <xsl:for-each>.

Uploaded by

Ryu Villota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

XSLT Introduction

XSL (eXtensible Stylesheet Language) is a


styling language for XML.

XSLT stands for XSL Transformations.

This XSLT is use to transform XML documents


into other formats (like transforming XML into
HTML).

1
Example code of XSLT

2
XSL = Style Sheets for XML
XML does not use predefined tags, and therefore the meaning of each
tag is not well understood.

A <table> element could indicate an HTML table, a piece of furniture,


or something else - and browsers do not know how to display it!

XSL describes how the XML elements should be displayed.

LANGUAGES
XSLT is a language for transforming XML documents.
XPath is a language for navigating in XML documents.
XQuery is a language for querying XML documents.

3
Correct Style Sheet Declaration
• The root element that declares the document to be an XSL
style sheet is <xsl:stylesheet> or <xsl:transform>.
Note: <xsl:stylesheet> and <xsl:transform> are completely
synonymous and either can be used!

The correct way to declare an XSL style sheet according to the W3C XSLT
Recommendation is:

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

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

4
XSLT <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).

<xsl:template match="/">

5
XSLT <xsl:value-of> Element
The <xsl:value-of> element can be used to extract the value of an
XML element and add it to the output stream of the transformation:

<xsl:value-of select=“root/parent/child"/>

6
XSLT <xsl:for-each> Element
The XSL <xsl:for-each> element can be used to select every XML element
of a specified node-set

<xsl:for-each select=“root/parent">

Note: The value of the select attribute is an XPath expression. An XPath


expression works like navigating a file system; where a forward slash (/) selects
subdirectories.

7
Filtering the Output
We can also filter the output from the XML file by adding a criterion to
the select attribute in the <xsl:for-each> element.
<xsl:for-each select=“root/parent[child_element=‘text']">
Legal filter operators are:
•= (equal)
•!= (not equal)
•&lt; less than
•&gt; greater than

8
XSLT <xsl:sort> Element
To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each>
element in the XSL file

<xsl:sort select=“element"/>

You might also like