More Related Content More from Vijay Kumar Verma More from Vijay Kumar Verma (10) XML XSLT3. α Extensible Stylesheet Language.
α A Formatting language.
α Vocabulary for describing the formatting
(i.e. layout) What of a document is XSL?
via "Formatting
Objects“
α Consist of Three part
XSLT
Xpath
XSL-FO
4. XML
(content)
XSL
(presentation)
How it Works?
XSL Parser
(Transformation engine)
XML, PDF, XHTML
5. α Here’s a simple XML document:
<?xml version="1.0"?>
<library>
Simple Xpath
<book>
<title edition=“2”>XML</title>
<author>Gregory Brill</author>
</book>
<book>
<title edition=“1”>Java and
XML</title>
<author>Brett McLaughlin</author>
</book>
</library >
Xpath Expressions
/library
/library/book
/library/book/title
/library/book/title/@edition
/library/book/title/[@edition=2]
/library/book[1]
//book[2]
/library/*
/library/book[1]/title/text()
6. Simple Xpath
α Here’s a simple XML document:
<?xml version="1.0"?>
<library>
<book>
<title edition=“2”>XML</title>
<author>Gregory Brill</author>
</book>
<book>
<title edition=“1”>Java and
XML</title>
<author>Brett McLaughlin</author>
</book>
</library >
Xpath Expressions
/library
/library/book
/library/book/title
/library/book/title/@edition
/library/book/title/[@edition=2]
/library/book[1]
//book[2]
/library/*
/library/book[1]/title/text()
7. α Here’s a simple XML document:
<?xml version="1.0"?>
<library>
<book>
<title edition=“2”>XML</title>
<author>Gregory Brill</author>
</book>
<book>
<title edition=“1”>Java and
XML</title>
<author>Brett McLaughlin</author>
</book>
</library >
Xpath Expressions
/library
/library/book
/library/book/title
/library/book/title/@edition
/library/book/title/[@edition=2]
/library/book[1]
//book[2]
/library/*
/library/book[1]/title/text()
Simple Xpath
8. α Here’s a simple XML document:
<?xml version="1.0"?>
<library>
<book>
<title edition=“2”>XML</title>
<author>Gregory Brill</author>
</book>
<book>
<title edition=“1”>Java and
XML</title>
<author>Brett McLaughlin</author>
</book>
</library >
Xpath Expressions
/library
/library/book
/library/book/title
/library/book/title/@edition
/library/book/title/[@edition=2]
/library/book[1]
//book[2]
/library/*
/library/book[1]/title/text()
Simple Xpath
9. α Here’s a simple XML document:
<?xml version="1.0"?>
<library>
<book>
<title edition=“2”>XML</title>
<author>Gregory Brill</author>
</book>
<book>
<title edition=“1”>Java and
XML</title>
<author>Brett McLaughlin</author>
</book>
</library >
Xpath Expressions
/library
/library/book
/library/book/title
/library/book/title/@edition
/library/book/title/[@edition=2]
/library/book[1]
//book[2]
/library/*
predicate
/library/book[1]/title/text()
Simple Xpath
10. α Here’s a simple XML document:
<?xml version="1.0"?>
<library>
<book>
<title edition=“2”>XML</title>
<author>Gregory Brill</author>
</book>
<book>
<title edition=“1”>Java and
XML</title>
<author>Brett McLaughlin</author>
</book>
</library >
Xpath Expressions
/library
/library/book
/library/book/title
/library/book/title/@edition
/library/book/title/[@edition=2]
/library/book[1]
//book[2]
/library/*
/library/book[1]/title/text()
Simple Xpath
11. α Here’s a simple XML document:
<?xml version="1.0"?>
<library>
<book>
<title edition=“2”>XML</title>
<author>Gregory Brill</author>
</book>
<book>
<title edition=“1”>Java and
XML</title>
<author>Brett McLaughlin</author>
</book>
</library >
Xpath Expressions
/library
/library/book
/library/book/title
/library/book/title/@edition
/library/book/title/[@edition=2]
/library/book[1]
//book[2]
/library/*
/library/book[1]/title/text()
Simple Xpath
12. α Here’s a simple XML document:
<?xml version="1.0"?>
<library>
<book>
<title edition=“2”>XML</title>
<author>Gregory Brill</author>
</book>
<book>
<title edition=“1”>Java and
XML</title>
<author>Brett McLaughlin</author>
</book>
</library >
Xpath Expressions
/library
/library/book
/library/book/title
/library/book/title/@edition
/library/book/title/[@edition=2]
/library/book[1]
//book[2]
/library/*
/library/book[1]/title/text()
Simple Xpath
13. α Here’s a simple XML document:
<?xml version="1.0"?>
<library>
<book>
<title edition=“2”>XML</title>
<author>Gregory Brill</author>
</book>
<book>
<title edition=“1”>Java and
XML</title>
<author>Brett McLaughlin</author>
</book>
</library >
Xpath Expressions
/library
/library/book
/library/book/title
/library/book/title/@edition
/library/book/title/[@edition=2]
/library/book[1]
//book[2]
/library/*
/library/book[1]/title/text()
Simple Xpath
14. α Extensible Stylesheet Language
Transformations
α XSLT1.0 accepted in 1999 as W3C standard
α XSLT2.0 just reached recommendation level
What is XSLT?
in January 2007.
α XSLT is designed for use as part of XSL,
which is a stylesheet language for XML.
α Use XML Syntax.
α Can be used like a stylesheet or embedded
in a programming language.
15. <xsl:stylesheet version=“1.0”
xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>
<xsl:import/>
<xsl:include/>
<xsl:strip-space/>
<xsl:preserve-space/>
<xsl:output/>
<xsl:key/>
<xsl:decimal-format/>
<xsl:namespace-alias/>
<xsl:attribute-set>...</xsl:attribute-set>
<xsl:variable>...</xsl:variable>
<xsl:param>...</xsl:param>
<xsl:template match=“...”>
Syntax and structure
...
</xsl:template>
<xsl:template name=“...”>
...
</xsl:template
</xsl:stylesheet>
18. <?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet href=bird.xsl" type="text/xsl"?>
<zoo>
XML File
<bird>
<name>Peacock</name>
<size>Large</size>
</bird>
<bird>
<name>Sparrow</name>
<size>Small</size>
</bird>
<bird>
<name>peagion</name>
<size>medium</size>
</bird>
</zoo>
19. <?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
XSL File
<head>
<title>Bird in Zoo</title>
</head>
<body>
<xsl:for-each select="zoo/bird">
<ol>
<li><xsl:value-of select="name"/></li>
<li><xsl:value-of select="size"/></li>
</ol>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
21. <xsl:for-each select="//book">
loops through every book element, everywhere in the
document
<xsl:value-of select="title"/>
chooses the content of the title element at the
current location
Summary of XSL file
<xsl:for-each select="//book">
<xsl:value-of select="title"/>
</xsl:for-each>
chooses the content of the title element for each
book in the XML document
22. <?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//bird">
<html>
<head>
<title>Bird in Zoo</title>
</head>
<body>
Another XSL File
<xsl:if test="name='peagion'">
<h1>Size of peagion: <xsl:value-of select="size"
/></h1>
</xsl:if>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
24. <?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//bird">
<html>
<head>
<title>Bird in Zoo</title>
</head>
<body>
Choose, when, <xsl:choose>
otherwise
<xsl:when test="name='peagion'">
<h1>Symbol of peace.</h1>
</xsl:when>
<xsl:when test="name='Peacock'">
<h1>National Bird</h1>
</xsl:when>
<xsl:otherwise>
<h1>Simple Bird</h1>
</xsl:otherwise>
</xsl:choose>
</body></html></xsl:template></xsl:stylesheet>