The document discusses various XML transformation languages including XSLT, XPath, and XQuery. It provides definitions and examples of how each works. XSLT is used to transform XML documents into other XML or XHTML documents using templates and XPath for navigation. XPath allows selecting nodes in an XML document. XQuery is used to query XML data similar to how SQL is used to query databases. Examples are given of XSLT and XQuery syntax and usage.
2. An XML transformation language is
a programming language designed
specifically to transform
an input XML document into an output
document which satisfies some specific goal.
There are two special cases of
transformation:
XML to XML: the output document is an XML
document.
XML to Data: the output document is a byte
stream.
3. XSLT
- XSLT is a language for transforming
XML documents into XHTML documents or
to other XML documents.
XPATH
- XPath is a language for navigating in XML
documents.
XQUERY
- XQuery was designed to query XML data.
4. XSLT stands for XSL Transformations
XSLT is the most important part of XSL
XSL stands for
EXtensible Stylesheet Language.
XSL describes how the XML document should
be displayed
XSLT transforms an XML document into
another XML document
XSLT uses XPath to navigate in XML
documents
XSLT is a W3C Recommendation
5. 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/Tr
ansform">
Or
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Tr
ansform">
6. XPath is used to navigate through elements and
attributes in an XML document.
XPath is a syntax for defining parts of an XML
document
XPath uses path expressions to navigate in XML
documents
XPath contains a library of standard functions
XPath is a major element in XSLT
XPath is a W3C recommendation
XPath uses path expressions to select nodes or
node-sets in an XML document.
7.
8.
9. 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).
10. The <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
The <xsl:for-each> Element
The XSL <xsl:for-each> element can be used
to select every XML element of a specified
node-set:
11. Example:
We want to transform the following XML document ("cdcatalog.xml") into HTML:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>USA</country>
<company>Columbia</company>
<price>20.90</price>
<year>1986</year>
</cd>
</catalog>
Save it as cdcatalog.xml
12. Then you create an XSL Style Sheet ("cdcatalog.xsl") with a transformation template:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
13. Add the XSL style sheet reference to your XML document ("cdcatalog.xml"):
<?xml version="1.0" encoding="UTF-8"?>
<?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>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>USA</country>
<company>Columbia</company>
<price>20.90</price>
<year>1986</year>
</cd>
</catalog>
14.
15. XQuery is designed to query XML data - not
just XML files, but anything that can appear
as XML, including databases.
XQuery is the language for querying XML data
XQuery for XML is like SQL for databases
XQuery is built on XPath expressions
XQuery is supported by all major databases
XQuery is a W3C Recommendation
XQuery is a language for finding and
extracting elements and attributes from XML
documents.
16. Functions
XQuery uses functions to extract data from
XML documents.
The doc() function is used to open the
"books.xml" file:
doc("books.xml")
17. Path Expressions
XQuery uses path expressions to navigate
through elements in an XML document.
The following path expression is used to
select all the title elements in the "books.xml"
file:
doc("books.xml")/bookstore/book/title
(/bookstore selects the bookstore element,
/book selects all the book elements under the
bookstore element, and /title selects all the
title elements under each book element)
18. doc("books.xml")/bookstore/book[price>30]/
title
The expression above will select all the title
elements under the book elements that are
under the bookstore element that have a
price element with a value that is higher than
30.
19. XLink is short for XML Linking Language
XLink is used to create hyperlinks in XML
documents
Any element in an XML document can behave as
a link
XLink supports simple links (like HTML) and
extended links (for linking multiple resources
together)
With XLink, the links can be defined outside the
linked files
XLink is a W3C Recommendation