3. Warming up…
What does XML stand for ?
eXtensible Markup Language
Extensible means that there is no fixed
tag set (like in HTML)
4. Overview
Stands for “eXtensible Stylesheet
Language Transformations”
Language for transforming an input xml
document into output document.
Navigation of input XML document is
through XPath
Output document may be XML or any other
text format.
6. Language
Syntax defined by W3C
XSLT stylesheet file is an XML file
XSLT is based on the programming
paradigm of pattern matching.
XSLT is based on concepts of functional
programming as a stylesheet is made up of
templates, which are essentially pure
functions.
<xsl:stylesheet version=“1.0”
xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>
7. Simple Example
Sample xml File
Sample Output required in csv format
<?xml version=“1.0”?>
<ContactInfo>
<Person>
<Name>Rajiv Poplai</Name>
<Mobile>9810766277</Mobile>
</Person>
</ContactInfo>
Rajiv Poplai, 9810766277
9. <xsl:template> Element
An xsl:template element essentially tells the
XSLT processor, “as you go through the
source tree, when you find a node of that tree
whose name matches the value of my match
attribute, add my contents to the result tree.”
11. Test your knowledge
What would an XSLT processor do with a stylesheet that contained
no template rules?
For example what would be the output if the stylesheet below:
is applied to the XML file below
12. Answer
XSLT has several built-in default templates that tell
the XSLT processor to output the text content of the
elements, leaving out the attributes and markup.
13. Other constructs
Tasks Construct (Instructions)
Creating new nodes <xsl:document>, <xsl:element>,
<xsl:attribute>, <xsl:text>, <xsl:value-of>
Iteration (process all nodes of a given
node set)
<xsl:for-each>
Conditional <xsl:if>, <xsl:choose>
Numbering <xsl:number>
Combining Stylesheets <xsl:include>, <xsl:import>
Sorting (sort a nodeset based on some
criteria)
<xsl:sort>
Variables <xsl:variable>, <xsl:param>
Invoking templates <xsl:apply-templates> (find a template
for each node in the input sequence)
<xsl:call-template>