Extensible Stylesheet Language (XSL) Atul Kahate [email_address]
Introduction to XSLT Concepts
XSL (XML Stylesheet Language) <ul><li>Two parts </li></ul><ul><ul><li>XSLT (XSL Transformation) </li></ul></ul><ul><ul><li...
XPath <ul><li>Allows searching and navigation of XML documents </li></ul><ul><li>Can specify which parts of an XML documen...
XSLT Usage <ul><li>Styling </li></ul><ul><li>Add elements specific to viewing (e.g. logo) </li></ul><ul><li>Create new con...
XSLT Stylesheets <ul><li>An XSLT  stylesheet  consists of a series of  templates , together with instructions based on XPa...
XSLT Processing Concept Input XML document XSLT Processor Output XML document XSLT Template XSLT Stylesheet
XSLT Basics
XSLT Example – 1  <ul><li>Consider the following XML document </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul>...
XSLT Example – 2  <ul><li>Here is the corresponding XSLT document </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot...
Be Careful! <ul><li>When we say <xsl:template-match>, we not only attempt to locate the specified element/position, but ac...
Now try these <ul><li><xsl:template match=&quot;/&quot;> and remaining things unchanged </li></ul><ul><ul><li>Now the path...
First XSL Example: Hello World! <ul><li>XML Document (HelloWorld.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; ...
Second XSL example <ul><li>XML Document (second.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UT...
Exercise <ul><li>Write an XSLT document for the following XML document to display it as HTML </li></ul><ul><li><?xml versi...
Solution <ul><li><xsl:stylesheet version = “1.0” xmlns:xsl = “http://www/w3.org/1999/XSL/Transform”> </li></ul><ul><li><xs...
Exercise <ul><li>Consider the following XML file: </li></ul><ul><li><?xml version=“1.0”?> </li></ul><ul><li><BOOK> </li></...
Solution <ul><li><xsl:stylesheet version=“1.0” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> </li></ul><ul><li><xsl:te...
Exercise <ul><li>Consider this XML and write an XSL to display only the book title and price </li></ul><ul><li><?xml versi...
Solution <ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li>...
Exercise <ul><li>Consider the following XML document, titled emp.xml: </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </...
Solution <ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li>...
Simple XSLT Example <ul><li>XML (test.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><l...
To understand better … <ul><li>Make changes to the XSL as follows: </li></ul><ul><ul><li><h1><xsl:value-of select=&quot;/t...
Change to the XML <ul><li>The XML document has an < xml-stylesheet>  tag, which informs the parser that we want to use an ...
Now look at the XSL <ul><li>The XSLT stylesheet is also a well-formed XML document </li></ul><ul><li>The <xsl:stylesheet> ...
Question <ul><li>What if our XML document has multiple occurrences of the  title  and  author  tags? </li></ul><ul><ul><li...
Modified XSL <ul><li><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >  </li></ul><ul><li><xsl:template m...
Interesting Tricks – 1 <ul><li>XML (trick-1.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul>...
Answer <ul><li>The full XML contents </li></ul><ul><li>Why? </li></ul><ul><ul><li>If no template is specified, XSLT produc...
Interesting Tricks – 2 <ul><li>XML (trick-2.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul>...
Answer <ul><li>Now we have said, match root, but once root is matched, we say do nothing (since there is nothing between <...
Interesting Tricks – 3 <ul><li>XML (trick-3.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul>...
Answer <ul><li>Now, we try to find a match on the title element inside /. </li></ul><ul><li>But the path for title should ...
Interesting Tricks – 4 <ul><li>XML (trick-4.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul>...
Answer <ul><li>It would produce the contents of the title element, as expected, now </li></ul>
Template Basics
Usage of Templates <ul><li><xsl:template match = “…”> </li></ul><ul><ul><li>We know that this clause is used to match a pa...
Understanding <apply-templates> <ul><li>class.xml </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8...
How it Works? <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>  <?xml-stylesheet type=&quot;text/xsl&quot; href=...
Plain English Version <ul><li>For all the elements in the given XML </li></ul><ul><ul><li>If the current element = “studen...
Explanation <ul><li>The way this works is: </li></ul><ul><ul><li>Use a template if one defined </li></ul></ul><ul><ul><li>...
Notes on the Result – 1 <ul><li>Note that we would see display for  all  the student tags </li></ul><ul><li>However, in th...
Notes on the Result – 2 <ul><li>This style of coding is ambiguous! </li></ul><ul><li>It can lead to completely unexpected ...
Modified XML and XSL <ul><li>class1.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>   </l...
Output <ul><li>Bye10000 </li></ul><ul><li>Why? </li></ul><ul><ul><li>The attempt is to find a match for the tag or element...
Further Modifications <ul><li>Modified XML </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>   ...
Still More Changes <ul><li>class3.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>   </li>...
Output <ul><li>Found a learner!  </li></ul><ul><li>This is because we have suppressed the output for the salary tag now </...
Introducing apply-templates
Third XSL Example <ul><li>XML document (third.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-...
Use of <apply-templates>  - Tricky <ul><li>class2.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8...
Output <ul><li>Testone10000two20000three30000 </li></ul><ul><li>Reason: The logic works as: </li></ul><ul><ul><li>If there...
Suppressing Unwanted Output <ul><li>Modified XSL </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot...
Controlling the Output the Way We Want (Earlier student example)
XSL Changed – 1 <ul><li>Now changes the XSL to this: </li></ul><ul><li><?xml version=&quot;1.0&quot; ?>  </li></ul><ul><li...
Plain English Version <ul><li>For each element in the given XML </li></ul><ul><ul><li>If the current element is class </li...
Output of the second XSL <ul><li>Found a learner! Found a learner! Found a learner! </li></ul><ul><li>Explanation </li></u...
Beware of this Problem! <ul><li>Suppose the XSL was like this: </li></ul><ul><li><?xml version=&quot;1.0&quot; ?>  </li></...
Analysis <ul><li>The only change we have made is to remove the  select  attribute from  apply-templates </li></ul><ul><li>...
Plain English Version <ul><li>For each element in the given XML </li></ul><ul><ul><li>If the current element is class </li...
What about this? <ul><li>XML </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>   </li></ul><ul>...
Output <ul><li>SICSR Found a learner! Found a learner! Found a learner! Mr. Bean </li></ul><ul><li>Explanation </li></ul><...
Another Variation <ul><li>XML </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>   </li></ul><ul...
Summary <ul><li>Do not leave our code in an ambiguous state </li></ul><ul><li>This happens if we specify  <apply-templates...
Using Parameters in Templates
Using Parameters in Templates <ul><li><xsl:template name = &quot;print&quot; >  </li></ul><ul><li><xsl:param name = &quot;...
Calling Templates <ul><li><xsl:template match = &quot;/&quot; >  </li></ul><ul><li><xsl:call-template name = &quot;print&q...
Code <ul><li>XML </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet type=&q...
Attributes
Dealing with Attributes <ul><li>XML </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml...
Another Example <ul><li>XML </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><?xml-stylesheet href=&quo...
A Detailed Example
discussionForumHome.xml <ul><li><? xml   version =&quot;1.0&quot;  encoding =&quot;utf-8&quot;?> </li></ul><ul><li><? xml-...
discussionForumHome.xsl <ul><li><? xml   version =&quot;1.0&quot;  encoding =&quot;utf-8&quot;?> </li></ul><ul><li>< xsl:s...
<xsl:template match = “/”> <ul><li>Read this as: Start processing the XML document at the root of the document </li></ul><...
Understanding  <xsl:template-match>  - 1 <ul><li>< xsl:template   match =&quot;/&quot;> </li></ul><ul><li>< html > </li></...
Understanding  <xsl:template-match>  - 2 <ul><li><xsl:template match> </li></ul><ul><ul><li>Has four optional attributes <...
Understanding  <xsl:template-match>  - 3 <ul><li>But the XSLT also has one more <xsl:template> element as follows: </li></...
<xsl:apply-templates> - 1 <ul><li>Tells the XSLT processor to  </li></ul><ul><ul><li>Begin a new search for elements in th...
<xsl:apply-templates> - 2 <ul><li>The <xsl:apply-templates> element works recursively </li></ul><ul><li>Here, it tells the...
<xsl:apply-templates> - 3 <ul><li>Assuming that the XSLT processor locates the <discussionForumHome> element, it searches ...
<xsl:template match = “messageBoard”> <ul><li>This template gets invoked for each instance of the <messageBoard> element <...
Summary <ul><li>Most transformation in  XSLT is driven by two elements, <xsl:template> and <xsl:apply-templates>. </li></u...
Comparing <xsl:template> to <xsl:apply-template> <ul><li>Think about the former as similar to a Java method definition, an...
Controlling the Output Method <ul><li>Try adding  </li></ul><ul><ul><li><xsl:output method=“html” /> </li></ul></ul><ul><u...
Quick Recap
Source XML (apply.xml) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot...
Basic XSL Example (apply0.xml) <ul><li><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version=&quot;1.0&...
Explanation <ul><li>We have not specified what action should be taken when root is applied </li></ul><ul><li>This causes t...
XSL Example: 1 (apply1.xsl) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&qu...
Explanation <ul><li>Now there is an <apply-templates> inside the <template match> </li></ul><ul><li>This causes the defaul...
XSL Example: 2 (apply2.xsl) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&qu...
Explanation <ul><li>Empty output, since  <apply-templates/>  will bring search from the root level to all non-root element...
XSL Example: 3 (apply3.xsl) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&qu...
XSL Example: 4 (apply4.xsl) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&qu...
XSL Example: 6 (apply6.xsl)  - Tricky <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&q...
XSL Example: 5 (apply5.xsl) –  Tricky! <ul><li>What if we remove all search paths except the absolute ones? </li></ul><ul>...
Explanation <ul><li>Here, there is no <apply-templates> calling any of the defined <template match> tags </li></ul><ul><li...
Using the Mode Attribute
Using Mode <ul><li>If more than one template matches an identical pattern, a conflict arises </li></ul><ul><li>This can be...
Mode Example, also uses CSS <ul><li>XML (css-example-1) </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF...
Creating New Elements and Attributes
Creating Elements and Attributes <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><students> </li></ul><ul><li><s...
Corresponding XSL <ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quo...
Explanation - 1 <ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xs...
Explanation – 2 <ul><li><xsl:template match=&quot;students&quot;> </li></ul><ul><li><students> </li></ul><ul><li><xsl:appl...
Explanation – 3 <ul><li><xsl:template match=&quot;student&quot;> </li></ul><ul><li><xsl:element name=&quot;{@first_name}&q...
Explanation – 4 <ul><li><xsl:attribute name=&quot;id&quot;> </li></ul><ul><li><xsl:value-of select=&quot;id&quot;/> </li><...
Explanation – 5 <ul><li><notes> </li></ul><ul><li><xsl:value-of select=&quot;remarks&quot;/> </li></ul><ul><li></notes> </...
Explanation – 6 <ul><li>Input XML </li></ul><ul><ul><li><student first_name=&quot;Raju&quot;> </li></ul></ul><ul><ul><li><...
Running the Example <ul><li>set CLASSPATH=d:xalanbinxalan.jar;d:xalanbinxerces-Impl.jar </li></ul><ul><li>java org.apache....
Xalan and Xerces <ul><li>Xalan: Fully implements XSLT, XPath, and JAXP </li></ul><ul><li>Xerces: Implements XML specificat...
Looping using for-each
Example: Change XML Contents into an HTML Table – XML File <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1...
Example: Change XML Contents into an HTML Table – XSL File <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1...
Exercise <ul><li>Display name, address, and phone number for all customers in a table </li></ul><ul><li><?xml version=&quo...
Solution <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; </li></ul><ul><...
Exercise <ul><li>Achieve the same results without using for-each </li></ul>
Solution <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot...
Another for-each Example
Exercise: XML <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet href=&...
Solution: XSL <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><xsl:stylesheet version...
Sorting Data
Sorting <ul><li>XML </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href...
Sorting Information <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> </li></ul><ul><li><xsl:stylesh...
Sorting – Another Example – XML File <ul><li><?xml version=&quot;1.0&quot; ?> </li></ul><ul><li><famous-persons> </li></ul...
Sorting – Another Example – XSLT <ul><li>Write an XSLT for sorting data appropriately </li></ul>
Sorting and Data Types – 1 <ul><li>XML </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?...
Sorting and Data Types – 2 <ul><li>Modified XSL </li></ul><ul><ul><li><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XS...
Sorting on Multiple Keys <ul><li>Specify multiple  xsl:sort  elements, one after the other </li></ul><ul><li>Example </li>...
Another Sort Example <ul><li>sort-1.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li>...
Producing HTML Output <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:styleshee...
Output Using HTML Table <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><xsl:styleshe...
Sorting on Attributes and Formatting <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>...
Another Sort Example for Multiple Fields <ul><li>item-list.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&q...
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
4   xslt
Upcoming SlideShare
Loading in...5
×

4 xslt

1,495

Published on

XSLT

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,495
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
75
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

4 xslt

  1. 1. Extensible Stylesheet Language (XSL) Atul Kahate [email_address]
  2. 2. Introduction to XSLT Concepts
  3. 3. XSL (XML Stylesheet Language) <ul><li>Two parts </li></ul><ul><ul><li>XSLT (XSL Transformation) </li></ul></ul><ul><ul><li>XSL-FO (XSL Formatting Objects) </li></ul></ul><ul><li>XSLFO is similar to CSS, quite complex </li></ul><ul><li>We will discuss XSLT in detail, XSL-FO in brief </li></ul>
  4. 4. XPath <ul><li>Allows searching and navigation of XML documents </li></ul><ul><li>Can specify which parts of an XML document we want to transform </li></ul><ul><li>Used heavily in XSLT for searching of information </li></ul>
  5. 5. XSLT Usage <ul><li>Styling </li></ul><ul><li>Add elements specific to viewing (e.g. logo) </li></ul><ul><li>Create new content from existing one (e.g. TOC) </li></ul><ul><li>Present information with the right level of details (e.g. overview for managers, details for staff) </li></ul><ul><li>Transform XML documents into HTML </li></ul>
  6. 6. XSLT Stylesheets <ul><li>An XSLT stylesheet consists of a series of templates , together with instructions based on XPath </li></ul><ul><li>Tell an XSLT processor how to match the template against the nodes in an XML input document </li></ul><ul><li>For each template, the processor reads the input document for all matching patterns and produces an output document </li></ul><ul><li>See next slide </li></ul>
  7. 7. XSLT Processing Concept Input XML document XSLT Processor Output XML document XSLT Template XSLT Stylesheet
  8. 8. XSLT Basics
  9. 9. XSLT Example – 1 <ul><li>Consider the following XML document </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;pune.xsl&quot;?> </li></ul><ul><li><content> </li></ul><ul><li><about> PUNE </about> </li></ul><ul><li><city> </li></ul><ul><li><line1> Pune is a lovely city </line1> </li></ul><ul><li><line2> The education facilities are as best as you can get </line2> </li></ul><ul><li><line3> And the weather is great, too. </line3> </li></ul><ul><li></city> </li></ul><ul><li></content> </li></ul>
  10. 10. XSLT Example – 2 <ul><li>Here is the corresponding XSLT document </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;content&quot;> </li></ul><ul><li><html> </li></ul><ul><li><head><title>Welcome to Pune!</title></head> </li></ul><ul><li><body> </li></ul><ul><li><h1><xsl:value-of select=&quot;about&quot;/></h1> </li></ul><ul><li><h2><xsl:value-of select=&quot;city/line1&quot;/></h2> </li></ul><ul><li><h3><xsl:value-of select=&quot;city/line2&quot;/></h3> </li></ul><ul><li><h4><xsl:value-of select=&quot;city/line3&quot;/></h4> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  11. 11. Be Careful! <ul><li>When we say <xsl:template-match>, we not only attempt to locate the specified element/position, but actually move the XSLT cursor there </li></ul><ul><li>Example </li></ul><ul><ul><li><xslt:template-match = “content”> </li></ul></ul><ul><ul><ul><li>Takes cursor to the content element in XML </li></ul></ul></ul><ul><ul><ul><ul><li>Hence, later when we say <xsl:value-of select=&quot;about&quot;/>, XSLT completes the Xpath as /content/about OR </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Hence, later when we say <xsl:value-of select=“city/line1&quot;/>, XSLT completes the Xpath as /content/city/line1 </li></ul></ul></ul></ul>
  12. 12. Now try these <ul><li><xsl:template match=&quot;/&quot;> and remaining things unchanged </li></ul><ul><ul><li>Now the path for searching is /about, /city/line1, etc; which is incorrect </li></ul></ul><ul><li><xsl:template match=&quot;/content&quot;> and remaining things unchanged </li></ul><ul><li><xsl:template match=&quot;/content&quot;>, <h1><xsl:value-of select=&quot;/about&quot;/></h1> and remaining things unchanged </li></ul><ul><li><xsl:template match=&quot;/city&quot;> and remaining things unchanged </li></ul>
  13. 13. First XSL Example: Hello World! <ul><li>XML Document (HelloWorld.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=&quot;HelloWorld.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><msg>Hello World! </li></ul></ul><ul><ul><li></msg> </li></ul></ul><ul><li>XSL Document (HelloWorld.xsl) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul></ul><ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul></ul><ul><ul><li><xsl:output method=&quot;text&quot;/> </li></ul></ul><ul><ul><li><xsl:template match=&quot;msg&quot;>Found it!</xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul>
  14. 14. Second XSL example <ul><li>XML Document (second.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=&quot;second.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><message>We can easily output XML using XSLT! </li></ul></ul><ul><ul><li></message> </li></ul></ul><ul><li>XSL Document (second.xsl) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul></ul><ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul></ul><ul><ul><li><xsl:output method=&quot;text&quot;/> </li></ul></ul><ul><ul><li><xsl:template match=&quot;/&quot;>Message in XML document is: <xsl:apply-templates/>!</xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul>
  15. 15. Exercise <ul><li>Write an XSLT document for the following XML document to display it as HTML </li></ul><ul><li><?xml version = “1.0” ?> </li></ul><ul><li><?xml:stylesheet type = “text/xsl” href = “one.xsl”?> </li></ul><ul><li><myPerson> </li></ul><ul><li><personName>Sachin Tendulkar</personName> </li></ul><ul><li></myPerson> </li></ul>
  16. 16. Solution <ul><li><xsl:stylesheet version = “1.0” xmlns:xsl = “http://www/w3.org/1999/XSL/Transform”> </li></ul><ul><li><xsl:template match = “myPerson”> </li></ul><ul><li><html> </li></ul><ul><li><body> </li></ul><ul><li><b> <xsl:value-of select = “personName”/> </b> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  17. 17. Exercise <ul><li>Consider the following XML file: </li></ul><ul><li><?xml version=“1.0”?> </li></ul><ul><li><BOOK> </li></ul><ul><li><BOOK_TITLE>Computer Networks</BOOK_TITLE> </li></ul><ul><li><AUTHOR>Tanenbaum</AUTHOR> </li></ul><ul><li></BOOK> </li></ul><ul><li>Use XSL to display title and author as level 1 and level 2 headers, respectively </li></ul>
  18. 18. Solution <ul><li><xsl:stylesheet version=“1.0” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> </li></ul><ul><li><xsl:template match=“BOOK”> </li></ul><ul><li><html> </li></ul><ul><li><head><title> Book Information </title></head> </li></ul><ul><li><body> </li></ul><ul><li> <h1><xsl:value-of select=“BOOK_TITLE”/></h1> </li></ul><ul><li> <h2>by <xsl:value-of select=“AUTHOR”/></h2> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  19. 19. Exercise <ul><li>Consider this XML and write an XSL to display only the book title and price </li></ul><ul><li><?xml version = &quot;1.0&quot; ?> </li></ul><ul><li><?xml:stylesheet type = &quot;text/xsl&quot; href = &quot;booksmultiple.xsl&quot;?> </li></ul><ul><li><CATALOG> </li></ul><ul><li><BOOK> </li></ul><ul><li><TITLE>Computer Networks</TITLE> </li></ul><ul><li><AUTHORS> </li></ul><ul><li><AUTHOR>Andrew Tanenbaum</AUTHOR> </li></ul><ul><li></AUTHORS> </li></ul><ul><li><PUBYEAR>2003</PUBYEAR> </li></ul><ul><li><PRICE>250</PRICE> </li></ul><ul><li></BOOK> </li></ul><ul><li><BOOK> </li></ul><ul><li><TITLE>Computer Fundamentals</TITLE > </li></ul><ul><li><AUTHORS> </li></ul><ul><li><AUTHOR>Rajaraman</AUTHOR> </li></ul><ul><li><AUTHOR>Ghosh</AUTHOR> </li></ul><ul><li></AUTHORS> </li></ul><ul><li><PUBYEAR>2002</PUBYEAR> </li></ul><ul><li><PRICE>250</PRICE> </li></ul><ul><li></BOOK> </li></ul><ul><li></CATALOG> </li></ul>
  20. 20. Solution <ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;BOOK&quot;> </li></ul><ul><li>Book Name: <xsl:value-of select=&quot;TITLE&quot;/> Price: <xsl:value-of select=&quot;PRICE&quot;/> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  21. 21. Exercise <ul><li>Consider the following XML document, titled emp.xml: </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;emp.xsl&quot;?> </li></ul><ul><li><EMP_INFO> </li></ul><ul><li><EMPLOYEE> </li></ul><ul><li><EMP_NAME empID=&quot;9662&quot;> </li></ul><ul><li><FIRST>Sachin</FIRST> </li></ul><ul><li><LAST>Tendulkar</LAST> </li></ul><ul><li></EMP_NAME> </li></ul><ul><li></EMPLOYEE> </li></ul><ul><li></EMP_INFO> </li></ul><ul><li>Write emp.xsl file mentioned above, which would: </li></ul><ul><ul><li>Display a heading Emp Name: , followed by the employee’s name. </li></ul></ul><ul><ul><li>Display the employee id below this, in a smaller font. </li></ul></ul>
  22. 22. Solution <ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;EMP_INFO&quot;> </li></ul><ul><li><html> </li></ul><ul><li><head><title>Emp Info!</title></head> </li></ul><ul><li> <body> </li></ul><ul><li> <h1>Emp Name: <xsl:value-of select=&quot;EMPLOYEE/EMP_NAME/FIRST&quot;/> </li></ul><ul><li><xsl:value-of select=&quot;EMPLOYEE/EMP_NAME/LAST&quot;/> </h1> </li></ul><ul><li><h3> <xsl:value-of select=&quot;EMPLOYEE/EMP_NAME/@empID&quot;/></h3> </li></ul><ul><li> </body> </li></ul><ul><li></html> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  23. 23. Simple XSLT Example <ul><li>XML (test.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=&quot;test.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><xslTutorial> </li></ul></ul><ul><ul><li><title>XSL</title> </li></ul></ul><ul><ul><li><author>John Smith</author> </li></ul></ul><ul><ul><li></xslTutorial> </li></ul></ul><ul><li>XSLT (test.xsl) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul></ul><ul><ul><li><xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;> </li></ul></ul><ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul></ul><ul><ul><li><H1><xsl:value-of select=&quot;//title&quot;/></H1> </li></ul></ul><ul><ul><li><H2><xsl:value-of select=&quot;//author&quot;/></H2> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul>
  24. 24. To understand better … <ul><li>Make changes to the XSL as follows: </li></ul><ul><ul><li><h1><xsl:value-of select=&quot;/title&quot;/></h1> </li></ul></ul><ul><ul><li><h2><xsl:value-of select=&quot;/author&quot;/></h2> </li></ul></ul><ul><li>Then as </li></ul><ul><ul><li><h1><xsl:value-of select=&quot;title&quot;/></h1> </li></ul></ul><ul><ul><li><h2><xsl:value-of select=&quot;author&quot;/></h2> </li></ul></ul><ul><li>Then as </li></ul><ul><ul><li><xsl:template match=&quot;//&quot;> </li></ul></ul><ul><ul><li><h1><xsl:value-of select=&quot;title&quot;/></h1> </li></ul></ul><ul><ul><li><h2><xsl:value-of select=&quot;author&quot;/></h2> </li></ul></ul><ul><li>Then as </li></ul><ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul></ul><ul><ul><li><h1><xsl:value-of select=&quot;/xslTutorial/title&quot;/></h1> </li></ul></ul><ul><ul><li><h2><xsl:value-of select=&quot;/xslTutorial/author&quot;/></h2> </li></ul></ul><ul><li>Then as </li></ul><ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul></ul><ul><ul><li><h1><xsl:value-of select=&quot;xslTutorial/title&quot;/></h1> </li></ul></ul><ul><ul><li><h2><xsl:value-of select=&quot;xslTutorial/author&quot;/></h2> </li></ul></ul>
  25. 25. Change to the XML <ul><li>The XML document has an < xml-stylesheet> tag, which informs the parser that we want to use an XSLT stylesheet to process this XML file before displaying its contents </li></ul>
  26. 26. Now look at the XSL <ul><li>The XSLT stylesheet is also a well-formed XML document </li></ul><ul><li>The <xsl:stylesheet> element has two attributes </li></ul><ul><ul><li>Version specifies the XSLT specifications version </li></ul></ul><ul><ul><li>Declares the namespace </li></ul></ul>
  27. 27. Question <ul><li>What if our XML document has multiple occurrences of the title and author tags? </li></ul><ul><ul><li>We would still see only the first occurrence, since we have not yet seen the recursion part of XSLT </li></ul></ul>
  28. 28. Modified XSL <ul><li><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' > </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><H2><xsl:value-of select=&quot;//author&quot;/></H2> </li></ul><ul><li><H1><xsl:value-of select=&quot;//title&quot;/></H1> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  29. 29. Interesting Tricks – 1 <ul><li>XML (trick-1.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=“trick-1.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><xslTutorial> </li></ul></ul><ul><ul><li><title>XSL</title> </li></ul></ul><ul><ul><li><author>John Smith</author> </li></ul></ul><ul><ul><li></xslTutorial> </li></ul></ul><ul><li>XSL (trick-1.xsl) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul></ul><ul><ul><li><xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul><ul><li>What would be the output? </li></ul>
  30. 30. Answer <ul><li>The full XML contents </li></ul><ul><li>Why? </li></ul><ul><ul><li>If no template is specified, XSLT produces the complete XML as output! </li></ul></ul>
  31. 31. Interesting Tricks – 2 <ul><li>XML (trick-2.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=“trick-2.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><xslTutorial> </li></ul></ul><ul><ul><li><title>XSL</title> </li></ul></ul><ul><ul><li><author>John Smith</author> </li></ul></ul><ul><ul><li></xslTutorial> </li></ul></ul><ul><li>XSL (trick-2.xsl) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul></ul><ul><ul><li><xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;> </li></ul></ul><ul><ul><li><xsl:template match=“/”> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul><ul><li>What would be the output? </li></ul>
  32. 32. Answer <ul><li>Now we have said, match root, but once root is matched, we say do nothing (since there is nothing between <xsl:template match = “/” and </xsl:template> tags </li></ul><ul><li>Hence, output is empty </li></ul>
  33. 33. Interesting Tricks – 3 <ul><li>XML (trick-3.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=“trick-3.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><xslTutorial> </li></ul></ul><ul><ul><li><title>XSL</title> </li></ul></ul><ul><ul><li><author>John Smith</author> </li></ul></ul><ul><ul><li></xslTutorial> </li></ul></ul><ul><li>XSL (trick-3.xsl) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul></ul><ul><ul><li><xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;> </li></ul></ul><ul><ul><li><xsl:template match=“/”> </li></ul></ul><ul><ul><li><xsl:value-of select = “title” /> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul><ul><li>What would be the output? </li></ul>
  34. 34. Answer <ul><li>Now, we try to find a match on the title element inside /. </li></ul><ul><li>But the path for title should be /xslTutorial/title </li></ul><ul><li>Hence, output would be empty </li></ul>
  35. 35. Interesting Tricks – 4 <ul><li>XML (trick-4.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=“trick-4.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><xslTutorial> </li></ul></ul><ul><ul><li><title>XSL</title> </li></ul></ul><ul><ul><li><author>John Smith</author> </li></ul></ul><ul><ul><li></xslTutorial> </li></ul></ul><ul><li>XSL (trick-4.xsl) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul></ul><ul><ul><li><xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot;> </li></ul></ul><ul><ul><li><xsl:template match=“/”> </li></ul></ul><ul><ul><li><xsl:value-of select = “/xslTutorial/title” /> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul><ul><li>What would be the output? </li></ul>
  36. 36. Answer <ul><li>It would produce the contents of the title element, as expected, now </li></ul>
  37. 37. Template Basics
  38. 38. Usage of Templates <ul><li><xsl:template match = “…”> </li></ul><ul><ul><li>We know that this clause is used to match a particular tag from an XML file and to do processing, accordingly </li></ul></ul><ul><li><xsl:template name = “…”> </li></ul><ul><ul><li>Allows us to define a template </li></ul></ul><ul><ul><li>Once such a template is defined, we can use <xsl:call-template name = “…”> to call that defined template </li></ul></ul>
  39. 39. Understanding <apply-templates> <ul><li>class.xml </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;class.xsl&quot;?> </li></ul></ul><ul><ul><li><class> </li></ul></ul><ul><ul><li><student>Jack</student> </li></ul></ul><ul><ul><li><student>Harry</student> </li></ul></ul><ul><ul><li><student>Rebecca</student> </li></ul></ul><ul><ul><li><teacher>Mr. Bean</teacher> </li></ul></ul><ul><ul><li></class> </li></ul></ul><ul><li>Class.xsl </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul></ul><ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul></ul><ul><ul><li><xsl:template match=“student&quot;> Found a learner! </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul><ul><li>Output </li></ul><ul><ul><li>Found a learner! Found a learner! Found a learner! Mr. Bean </li></ul></ul>
  40. 40. How it Works? <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;class.xsl&quot;?> <class> <student>Jack</student> <student>Harry</student> <student>Rebecca</student> <teacher>Mr. Bean</teacher> </class> <?xml version=&quot;1.0&quot; ?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;student&quot;> Found a learner! </xsl:template> </xsl:stylesheet> Step 1: For all matching student tags, display output Found a learner! Step 2: Come here and run the template recursively for all the student tags, displaying Found a learner! Step 3: For all tags other than student , there is no template in our XSL. Therefore, blindly output them, as they are!
  41. 41. Plain English Version <ul><li>For all the elements in the given XML </li></ul><ul><ul><li>If the current element = “student” </li></ul></ul><ul><ul><ul><li>Display “Found a learner” </li></ul></ul></ul><ul><ul><li>Else </li></ul></ul><ul><ul><ul><li>Display the actual contents of the element </li></ul></ul></ul><ul><ul><li>End-if </li></ul></ul><ul><li>End-For </li></ul>
  42. 42. Explanation <ul><li>The way this works is: </li></ul><ul><ul><li>Use a template if one defined </li></ul></ul><ul><ul><li>Blindly output the contents of the elements wherever there is no template defined </li></ul></ul><ul><li>For each <template match = “student”>, we display the text Found a learner! instead of the student name itself. </li></ul><ul><li>However, for the teacher tag, there is no <template match>. Therefore, its contents are displayed as they are. </li></ul>
  43. 43. Notes on the Result – 1 <ul><li>Note that we would see display for all the student tags </li></ul><ul><li>However, in the first example, we would have seen the output only for the first instance of title and author tags </li></ul><ul><li>Why? </li></ul><ul><ul><li>In the earlier example, there was no template , i.e. no recursion – the syntax used was value-of select </li></ul></ul><ul><ul><li>Now, we use a template , which introduces recursion </li></ul></ul>
  44. 44. Notes on the Result – 2 <ul><li>This style of coding is ambiguous! </li></ul><ul><li>It can lead to completely unexpected results </li></ul><ul><li>Let us modify our XML and XSL now </li></ul>
  45. 45. Modified XML and XSL <ul><li>class1.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;class1.xsl&quot;?> </li></ul><ul><li>< class > </li></ul><ul><li>< dept > Bye </ dept > </li></ul><ul><li>< salary > 10000 </ salary > </li></ul><ul><li></ class > </li></ul><ul><li>class1.xsl </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:template match =&quot; hello &quot;> Found a learner! </ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul><ul><li>What would be the output? </li></ul>
  46. 46. Output <ul><li>Bye10000 </li></ul><ul><li>Why? </li></ul><ul><ul><li>The attempt is to find a match for the tag or element hello in our XML document, which is not found </li></ul></ul><ul><ul><li>For other tags in the XML document (i.e. dept and salary), there is no template defined; so no special processing is needed for them, except blindly outputting their contents, as before! </li></ul></ul>
  47. 47. Further Modifications <ul><li>Modified XML </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;class1.xsl&quot;?> </li></ul><ul><li>< class > </li></ul><ul><li>< dept > Bye </ dept > </li></ul><ul><li>< salary > 10000 </ salary > </li></ul><ul><li>< name > </li></ul><ul><li>< first > test </ first > </li></ul><ul><li>< last > test </ last > </li></ul><ul><li></ name > </li></ul><ul><li></ class > </li></ul><ul><li>Resulting Output </li></ul><ul><li>Bye10000testtest </li></ul><ul><li>This is based on same logic as earlier </li></ul>
  48. 48. Still More Changes <ul><li>class3.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;class1.xsl&quot;?> </li></ul><ul><li>< class > </li></ul><ul><li>< dept > Bye </ dept > </li></ul><ul><li>< salary > 10000 </ salary ></ class > </li></ul><ul><li>class3.xsl </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:template match =&quot; dept &quot;> </li></ul><ul><li>Found a learner! </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; salary &quot;> </li></ul><ul><li></ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul>
  49. 49. Output <ul><li>Found a learner! </li></ul><ul><li>This is because we have suppressed the output for the salary tag now </li></ul>
  50. 50. Introducing apply-templates
  51. 51. Third XSL Example <ul><li>XML document (third.xml) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=&quot;third.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><name> </li></ul></ul><ul><ul><li><first>Sachin</first> </li></ul></ul><ul><ul><li><last> Tendukar</last> </li></ul></ul><ul><ul><li></name> </li></ul></ul><ul><li>XSL document (third.xsl) </li></ul><ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul></ul><ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul></ul><ul><ul><li><xsl:template match=&quot;name&quot;> </li></ul></ul><ul><ul><li><html> </li></ul></ul><ul><ul><li><head> </li></ul></ul><ul><ul><li><title>XSL Output Example</title> </li></ul></ul><ul><ul><li></head> </li></ul></ul><ul><ul><li><body> </li></ul></ul><ul><ul><li><p> </li></ul></ul><ul><ul><li><xsl:apply-templates select=&quot;first&quot;/> </li></ul></ul><ul><ul><li></p> </li></ul></ul><ul><ul><li><p> </li></ul></ul><ul><ul><li><xsl:apply-templates select=&quot;last&quot;/> </li></ul></ul><ul><ul><li></p> </li></ul></ul><ul><ul><li></body> </li></ul></ul><ul><ul><li></html> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul>
  52. 52. Use of <apply-templates> - Tricky <ul><li>class2.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; </li></ul><ul><li>href=&quot;class2.xsl&quot;?> </li></ul><ul><li><class> </li></ul><ul><li><college>test</college> </li></ul><ul><li><dept>one</dept> </li></ul><ul><li><salary>10000</salary> </li></ul><ul><li><dept>two</dept> </li></ul><ul><li><salary>20000</salary> </li></ul><ul><li><dept>three</dept> </li></ul><ul><li><salary>30000</salary></class> </li></ul><ul><li>Class2.xsl </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:template match =“ dept &quot;> <xsl:apply-templates /> </ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul>
  53. 53. Output <ul><li>Testone10000two20000three30000 </li></ul><ul><li>Reason: The logic works as: </li></ul><ul><ul><li>If there is at least one dept tag </li></ul></ul><ul><ul><ul><li><apply-templates> (which means, display the default output as it is, which means everything) </li></ul></ul></ul>
  54. 54. Suppressing Unwanted Output <ul><li>Modified XSL </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:template match =&quot; dept &quot;> </li></ul><ul><li>< xsl:apply-templates /> </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; salary &quot;> </li></ul><ul><li></ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul>
  55. 55. Controlling the Output the Way We Want (Earlier student example)
  56. 56. XSL Changed – 1 <ul><li>Now changes the XSL to this: </li></ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;class&quot;> </li></ul><ul><li><xsl:apply-templates select=&quot;student&quot;/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;student&quot;> </li></ul><ul><li>Found a learner! </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul><ul><li>What would be the output? See next slide. </li></ul>
  57. 57. Plain English Version <ul><li>For each element in the given XML </li></ul><ul><ul><li>If the current element is class </li></ul></ul><ul><ul><ul><li>If the child element of the current element is student </li></ul></ul></ul><ul><ul><ul><ul><li>Output Found a learner </li></ul></ul></ul></ul><ul><ul><ul><li>End-if </li></ul></ul></ul><ul><ul><li>End-if </li></ul></ul><ul><li>End-for </li></ul><ul><li>Note: There is no Else now! </li></ul>
  58. 58. Output of the second XSL <ul><li>Found a learner! Found a learner! Found a learner! </li></ul><ul><li>Explanation </li></ul><ul><ul><li><xsl:template match=&quot;class&quot;> </li></ul></ul><ul><ul><ul><li>The XSLT processor begins at the root element when looking for template matches. It finds a match for the root element class . </li></ul></ul></ul><ul><ul><li><xsl:apply-templates select=&quot;student&quot;/> </li></ul></ul><ul><ul><ul><li>In our template that matched class we use xsl:apply-templates which will check for template matches on all the children of class . The children of class in our XML document are student and teacher . </li></ul></ul></ul><ul><ul><ul><li>To have the teacher element &quot;Mr. Bean&quot; ignored, we use the select attribute of xsl:apply-templates to specify only student children. </li></ul></ul></ul><ul><ul><ul><li>The XSLT processor then goes searching templates that only match student elements. </li></ul></ul></ul><ul><ul><li><xsl:template match=&quot;student“> </li></ul></ul><ul><ul><ul><li>The processor finds the only other template in our XSLT, which prints out &quot;Found a learner!&quot; for each student element in the XML document. XSLT finds three students, so &quot;Found a learner!&quot; is displayed three times. </li></ul></ul></ul><ul><ul><ul><li>XSLT then finishes its processing and we are left with XSLT output that has eliminated the unwanted text, &quot;Mr. Bean!&quot; </li></ul></ul></ul>
  59. 59. Beware of this Problem! <ul><li>Suppose the XSL was like this: </li></ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;class&quot;> </li></ul><ul><li><xsl:apply-templates /> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;student&quot;> </li></ul><ul><li>Found a learner! </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul><ul><li>What would be the output? See next slide. </li></ul>
  60. 60. Analysis <ul><li>The only change we have made is to remove the select attribute from apply-templates </li></ul><ul><li>This would translate to something different! </li></ul><ul><li>See next slide </li></ul>
  61. 61. Plain English Version <ul><li>For each element in the given XML </li></ul><ul><ul><li>If the current element is class </li></ul></ul><ul><ul><ul><li>If the child element of the current element is student </li></ul></ul></ul><ul><ul><ul><ul><li>Output Found a learner </li></ul></ul></ul></ul><ul><ul><ul><li>Else </li></ul></ul></ul><ul><ul><ul><ul><li>Output the contents of the current element as they are </li></ul></ul></ul></ul><ul><ul><ul><li>End-if </li></ul></ul></ul><ul><ul><li>End-if </li></ul></ul><ul><li>End-for </li></ul><ul><li>Note: There is an Else now! </li></ul>
  62. 62. What about this? <ul><li>XML </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;class.xsl&quot;?> </li></ul><ul><li>< college > </li></ul><ul><li>< class > </li></ul><ul><li>< institution > SICSR </ institution > </li></ul><ul><li>< student > Jack </ student > </li></ul><ul><li>< student > Harry </ student > </li></ul><ul><li>< student > Rebecca </ student > </li></ul><ul><li>< teacher > Mr. Bean </ teacher > </li></ul><ul><li></ class > </li></ul><ul><li></ college > </li></ul><ul><li>XSL </li></ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:template match =&quot; class &quot;> </li></ul><ul><li>< xsl:apply-templates /> </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; student &quot;> </li></ul><ul><li>Found a learner! </li></ul><ul><li></ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul>
  63. 63. Output <ul><li>SICSR Found a learner! Found a learner! Found a learner! Mr. Bean </li></ul><ul><li>Explanation </li></ul><ul><ul><li>The same logic as earlier applies </li></ul></ul><ul><ul><li>If a match is found, do something; else display contents of current element blindly </li></ul></ul><ul><ul><li>Remember, we do not have a select attribute in the template </li></ul></ul><ul><ul><li>If we have it, what would happen? </li></ul></ul>
  64. 64. Another Variation <ul><li>XML </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;class.xsl&quot;?> </li></ul><ul><li>< college > </li></ul><ul><li>< class > </li></ul><ul><li>< institution > SICSR </ institution > </li></ul><ul><li>< student > Jack </ student > </li></ul><ul><li>< student > Harry </ student > </li></ul><ul><li>< student > Rebecca </ student > </li></ul><ul><li>< teacher > Mr. Bean </ teacher > </li></ul><ul><li></ class > </li></ul><ul><li></ college > </li></ul><ul><li>XSL </li></ul><ul><li><?xml version=&quot;1.0&quot; ?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:template match =&quot; class &quot;> </li></ul><ul><li>< xsl:apply-templates select =&quot; student &quot;/> </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; student &quot;> </li></ul><ul><li>Found a learner! </li></ul><ul><li></ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul><ul><li>Output </li></ul><ul><li>Found a learner! Found a learner! Found a learner! </li></ul>
  65. 65. Summary <ul><li>Do not leave our code in an ambiguous state </li></ul><ul><li>This happens if we specify <apply-templates> without any specific select attribute </li></ul><ul><li>It can also happen if we do not specify exact selection criteria inside <template match> </li></ul><ul><li>Output may not be as expected! </li></ul>
  66. 66. Using Parameters in Templates
  67. 67. Using Parameters in Templates <ul><li><xsl:template name = &quot;print&quot; > </li></ul><ul><li><xsl:param name = &quot;A&quot; /> </li></ul><ul><li><xsl:param name = &quot;B&quot; >111</xsl:param> </li></ul><ul><li><xsl:value-of select = &quot;$A&quot; /> </li></ul><ul><li><xsl:text > + </xsl:text> </li></ul><ul><li><xsl:value-of select = &quot;$B&quot; /> </li></ul><ul><li><xsl:text > = </xsl:text> </li></ul><ul><li><xsl:value-of select = &quot;$A+$B&quot; /> </li></ul><ul><li></xsl:template> </li></ul><ul><li>This defines a template (like a method) called as print </li></ul><ul><li>This template can receive two parameters, named A and B. B has a default value of 111. </li></ul><ul><li>The template prints the following as the output: </li></ul><ul><li>Value of A + Value of B = Sum of A and B </li></ul><ul><li>For example, if a caller calls this template with A = 10 and B = 20, the output will be: </li></ul><ul><li>10 + 20 = 30 </li></ul>
  68. 68. Calling Templates <ul><li><xsl:template match = &quot;/&quot; > </li></ul><ul><li><xsl:call-template name = &quot;print&quot; > </li></ul><ul><li> <xsl:with-param name = &quot;A&quot; >11</xsl:with-param> </li></ul><ul><li> <xsl:with-param name = &quot;B&quot; >33</xsl:with-param> </li></ul><ul><li></xsl:call-template> </li></ul><ul><li><xsl:call-template name = &quot;print&quot; > </li></ul><ul><li> <xsl:with-param name = &quot;A&quot; >55</xsl:with-param> </li></ul><ul><li></xsl:call-template> </li></ul><ul><li></xsl:template> </li></ul><ul><li>Now, we are calling the template defined earlier ( print ) twice in succession: first time passing A = 11 and B = 33; and second time passing A = 55 and not passing any value for B </li></ul><ul><li>Output (Full code on next slide): </li></ul><ul><li>11 + 33 = 44 </li></ul><ul><li>55 + 111 = 166 </li></ul><ul><li>Note : 111 was B’s default value in the print template on the previous slide </li></ul>
  69. 69. Code <ul><li>XML </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;1.xsl&quot; ?> </li></ul></ul><ul><ul><li><AAA > </li></ul></ul><ul><ul><li><BBB>bbb </BBB> </li></ul></ul><ul><ul><li><CCC>ccc </CCC> </li></ul></ul><ul><ul><li></AAA> </li></ul></ul><ul><li>XSL </li></ul><ul><ul><li><xsl:stylesheet xmlns:xsl = &quot;http://www.w3.org/1999/XSL/Transform&quot; version = &quot;1.0&quot; > </li></ul></ul><ul><ul><li><xsl:output method = &quot;text&quot; /> </li></ul></ul><ul><ul><li><xsl:template match = &quot;/&quot; > </li></ul></ul><ul><ul><li><xsl:call-template name = &quot;print&quot; > </li></ul></ul><ul><ul><li><xsl:with-param name = &quot;A&quot; >11</xsl:with-param> </li></ul></ul><ul><ul><li><xsl:with-param name = &quot;B&quot; >33</xsl:with-param> </li></ul></ul><ul><ul><li></xsl:call-template> </li></ul></ul><ul><ul><li><xsl:call-template name = &quot;print&quot; > </li></ul></ul><ul><ul><li><xsl:with-param name = &quot;A&quot; >55</xsl:with-param> </li></ul></ul><ul><ul><li></xsl:call-template> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li><xsl:template name = &quot;print&quot; > </li></ul></ul><ul><ul><li><xsl:param name = &quot;A&quot; /> </li></ul></ul><ul><ul><li><xsl:param name = &quot;B&quot; >111</xsl:param> </li></ul></ul><ul><ul><li><xsl:text > </li></ul></ul><ul><ul><li></xsl:text> </li></ul></ul><ul><ul><li><xsl:value-of select = &quot;$A&quot; /> </li></ul></ul><ul><ul><li><xsl:text > + </xsl:text> </li></ul></ul><ul><ul><li><xsl:value-of select = &quot;$B&quot; /> </li></ul></ul><ul><ul><li><xsl:text > = </xsl:text> </li></ul></ul><ul><ul><li><xsl:value-of select = &quot;$A+$B&quot; /> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul>
  70. 70. Attributes
  71. 71. Dealing with Attributes <ul><li>XML </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=&quot;test.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><xslTutorial> </li></ul></ul><ul><ul><li><dog name='Joe'> </li></ul></ul><ul><ul><li><data weight='18 kg' color=&quot;black&quot;/> </li></ul></ul><ul><ul><li></dog> </li></ul></ul><ul><ul><li></xslTutorial> </li></ul></ul><ul><li>XSL </li></ul><ul><ul><li><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> </li></ul></ul><ul><ul><li><xsl:template match=&quot;dog&quot;> </li></ul></ul><ul><ul><li><P><B><xsl:text> Dog: </xsl:text> </B> </li></ul></ul><ul><ul><li><xsl:value-of select=&quot;@name&quot;/></P> </li></ul></ul><ul><ul><li><P><B><xsl:text> Color: </xsl:text> </B> </li></ul></ul><ul><ul><li><xsl:value-of select=&quot;data/@color&quot;/></P> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul>
  72. 72. Another Example <ul><li>XML </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><?xml-stylesheet href=&quot;products.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul><ul><li><card type=&quot;simple&quot;> </li></ul><ul><li><name>John Doe</name> </li></ul><ul><li><title>CEO, Widget Inc.</title> </li></ul><ul><li><email>john.doe@widget.com</email> </li></ul><ul><li><phone>(202) 456-1414</phone> </li></ul><ul><li></card> </li></ul><ul><li>XSL </li></ul><ul><li><xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; version=&quot;1.0&quot; </li></ul><ul><li>xmlns=&quot;http://www.w3.org/1999/xhtml&quot;> </li></ul><ul><li><xsl:template match=&quot;card[@type='simple']&quot;> </li></ul><ul><li><html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;> </li></ul><ul><li><title>business card</title><body> </li></ul><ul><li><xsl:apply-templates select=&quot;name&quot;/> </li></ul><ul><li><xsl:apply-templates select=&quot;title&quot;/> </li></ul><ul><li><xsl:apply-templates select=&quot;email&quot;/> </li></ul><ul><li><xsl:apply-templates select=&quot;phone&quot;/> </li></ul><ul><li></body></html> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;card/name&quot;> </li></ul><ul><li><h1><xsl:value-of select=&quot;text()&quot;/></h1> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;email&quot;> </li></ul><ul><li><p>email: <a href=&quot;mailto:{text()}&quot;><tt> </li></ul><ul><li><xsl:value-of select=&quot;text()&quot;/> </li></ul><ul><li></tt></a></p> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  73. 73. A Detailed Example
  74. 74. discussionForumHome.xml <ul><li><? xml version =&quot;1.0&quot; encoding =&quot;utf-8&quot;?> </li></ul><ul><li><? xml-stylesheet href=&quot;discussionForumHome.xsl&quot; type=&quot;text/xsl&quot; ?> </li></ul><ul><li>< disussionForumHome > </li></ul><ul><li>< messageBoard id =&quot;1&quot; name =&quot;Java Programming&quot;/> </li></ul><ul><li>< messageBoard id =&quot;2&quot; name =&quot;XML Programming&quot;/> </li></ul><ul><li>< messageBoard id =&quot;3&quot; name =&quot;XSLT Programming&quot;/> </li></ul><ul><li></ disussionForumHome > </li></ul>
  75. 75. discussionForumHome.xsl <ul><li><? xml version =&quot;1.0&quot; encoding =&quot;utf-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot;1.0&quot; </li></ul><ul><li>xmlns:xsl =&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li>< xsl:template match =&quot;/&quot;> </li></ul><ul><li>< html > </li></ul><ul><li>< head > </li></ul><ul><li>< title >Discussion Forum Home Page</ title > </li></ul><ul><li></ head > </li></ul><ul><li>< body > </li></ul><ul><li>< h1 >Discussion Forum Home Page</ h1 > </li></ul><ul><li>< h3 >Please select a message board to view:</ h3 > </li></ul><ul><li>< ul > </li></ul><ul><li>< xsl:apply-templates select =&quot;disussionForumHome/messageBoard&quot;/> </li></ul><ul><li></ ul > </li></ul><ul><li></ body > </li></ul><ul><li></ html > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot;messageBoard&quot;> </li></ul><ul><li>< li > </li></ul><ul><li>< a href =&quot;viewForum?id={@id}&quot;> </li></ul><ul><li>< xsl:value-of select =&quot;@name&quot;/> </li></ul><ul><li></ a > </li></ul><ul><li></ li > </li></ul><ul><li></ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul>
  76. 76. <xsl:template match = “/”> <ul><li>Read this as: Start processing the XML document at the root of the document </li></ul><ul><li>/ indicates root </li></ul><ul><li>There are some details underneath, as explained next </li></ul>
  77. 77. Understanding <xsl:template-match> - 1 <ul><li>< xsl:template match =&quot;/&quot;> </li></ul><ul><li>< html > </li></ul><ul><li>< head > </li></ul><ul><li>< title >Discussion Forum Home Page</ title > </li></ul><ul><li></ head > </li></ul><ul><li>< body > </li></ul><ul><li>< h1 >Discussion Forum Home Page</ h1 > </li></ul><ul><li>< h3 >Please select a message board to view:</ h3 > </li></ul><ul><li>< ul > </li></ul><ul><li>< xsl:apply-templates select =&quot;disussionForumHome/messageBoard&quot;/> </li></ul><ul><li></ ul > </li></ul><ul><li></ body > </li></ul><ul><li></ html > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>Once root is located, start outputting HTML tags as shown, until the < xsl:apply-templates select =&quot;disussionForumHome/messageBoard&quot;/> is encountered </li></ul>
  78. 78. Understanding <xsl:template-match> - 2 <ul><li><xsl:template match> </li></ul><ul><ul><li>Has four optional attributes </li></ul></ul><ul><ul><ul><li>match – Almost always necessary, takes an Xpath expression as an argument. When the current node matches the node set defined in this expression, the template is executed. </li></ul></ul></ul><ul><ul><ul><li>name – Allows us to refer to the template from elsewhere in the document </li></ul></ul></ul><ul><ul><ul><li>priority – NA </li></ul></ul></ul><ul><ul><ul><li>mode – NA </li></ul></ul></ul>
  79. 79. Understanding <xsl:template-match> - 3 <ul><li>But the XSLT also has one more <xsl:template> element as follows: </li></ul><ul><ul><li>< xsl:template match =&quot;messageBoard&quot;> </li></ul></ul><ul><li>Why does this not get the processor’s attention? </li></ul><ul><li>This is because by default, only the root is loaded; all other templates must be explicitly called by other parts of the XSLT code, as we shall discuss shortly </li></ul>
  80. 80. <xsl:apply-templates> - 1 <ul><li>Tells the XSLT processor to </li></ul><ul><ul><li>Begin a new search for elements in the source XML document that match the search pattern </li></ul></ul><ul><ul><li>And to look for a matching <xsl:template> element in the XSLT for the same element </li></ul></ul><ul><li>Here, we have: </li></ul><ul><li>< xsl:apply-templates select =&quot;disussionForumHome/messageBoard&quot;/> </li></ul><ul><li>Hence, the XSLT processor searches for </li></ul><ul><ul><li>A pattern disussionForumHome/messageBoard in the XML document </li></ul></ul><ul><ul><li>A <template-match> element for the same in the XSLT document </li></ul></ul>
  81. 81. <xsl:apply-templates> - 2 <ul><li>The <xsl:apply-templates> element works recursively </li></ul><ul><li>Here, it tells the XSLT processor to first select the <discussionForumHome> elements of the current node </li></ul><ul><li>Current node here is the root element of the XML document </li></ul><ul><li>Hence, it selects all the <discussionForumHome> elements at the root level, which means just one element </li></ul><ul><li>However, if we had more elements with the same name deeper in the hierarchy, they would have been ignored </li></ul>
  82. 82. <xsl:apply-templates> - 3 <ul><li>Assuming that the XSLT processor locates the <discussionForumHome> element, it searches for all of its <messageBoard> children </li></ul><ul><li>For each <messageBoard> child, the processor looks for the template in our stylesheet that provides the best match </li></ul><ul><li>Since our stylesheet contains a template that exactly matches the <messageBoard> pattern, it is instantiated for each of the <messageBoard> elements in the source XML </li></ul>
  83. 83. <xsl:template match = “messageBoard”> <ul><li>This template gets invoked for each instance of the <messageBoard> element </li></ul><ul><li>< xsl:template match =&quot;messageBoard&quot;> </li></ul><ul><li>< li > </li></ul><ul><li>< a href =&quot;viewForum?id={@id}&quot;> </li></ul><ul><li>< xsl:value-of select =&quot;@name&quot;/> </li></ul><ul><li></ a > </li></ul><ul><li></ li > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>In each case, it produces a line item, consisting of a hyperlink, displaying the name attribute of the <messageBoard> element, and embedding the id attribute in the URL </li></ul>
  84. 84. Summary <ul><li>Most transformation in XSLT is driven by two elements, <xsl:template> and <xsl:apply-templates>. </li></ul><ul><li>Processing begins at root, and then: </li></ul><ul><ul><li>For each X in the current node, processor searches for all <xsl:template match = “pattern”> elements in the stylesheet that potentially match the node. </li></ul></ul><ul><ul><li>The selected <xsl:template match = “pattern”> is instantiated using node X as its current node. This templates typically copies data from the source XML, or produces brand new content in combination with the source data. </li></ul></ul><ul><ul><li>If the template contains <xsl:apply-templates select = “newPattern” />, a new current node is created and the process repeats recursively. </li></ul></ul>
  85. 85. Comparing <xsl:template> to <xsl:apply-template> <ul><li>Think about the former as similar to a Java method definition, and the later as invoking that method </li></ul>
  86. 86. Controlling the Output Method <ul><li>Try adding </li></ul><ul><ul><li><xsl:output method=“html” /> </li></ul></ul><ul><ul><li><xsl:output method=“xml” /> </li></ul></ul><ul><ul><li><xsl:output method=“text” /> </li></ul></ul><ul><li>one after the other </li></ul><ul><li>Run the example from the command prompt as: </li></ul><ul><ul><li>set CLASSPATH=d:xalanbinxalan.jar </li></ul></ul><ul><ul><li>java org.apache.xalan.xslt.Process -INDENT 3 -IN employee.xml -XSL employee.xsl -OUT output.html </li></ul></ul>
  87. 87. Quick Recap
  88. 88. Source XML (apply.xml) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;apply1.xsl&quot;?> </li></ul><ul><li><book> </li></ul><ul><li><title>Profesional XSL</title> </li></ul><ul><li><chapters> </li></ul><ul><li><chapter> </li></ul><ul><li><chapterNo>2</chapterNo> </li></ul><ul><li><chapterTopic>XPath</chapterTopic> </li></ul><ul><li><chapterAuthor>Andrew Watt</chapterAuthor> </li></ul><ul><li><chapterSections> </li></ul><ul><li><chapterSection>Section 1</chapterSection> </li></ul><ul><li><chapterSection>Section 2</chapterSection> </li></ul><ul><li><chapterSection>Section 3</chapterSection> </li></ul><ul><li><chapterSection>Section 4</chapterSection> </li></ul><ul><li><chapterSection>Section 5</chapterSection> </li></ul><ul><li><chapterSection>Section 6</chapterSection> </li></ul><ul><li></chapterSections> </li></ul><ul><li></chapter> </li></ul><ul><li><chapter> </li></ul><ul><li><chapterNo>3</chapterNo> </li></ul><ul><li><chapterTopic>XSLT Basics</chapterTopic> </li></ul><ul><li><chapterAuthor>Paul Spencer</chapterAuthor> </li></ul><ul><li><chapterSections> </li></ul><ul><li><chapterSection>Section 1</chapterSection> </li></ul><ul><li><chapterSection>Section 2</chapterSection> </li></ul><ul><li><chapterSection>Section 3</chapterSection> </li></ul><ul><li><chapterSection>Section 4</chapterSection> </li></ul><ul><li><chapterSection>Section 5</chapterSection> </li></ul><ul><li><chapterSection>Section 6</chapterSection> </li></ul><ul><li></chapterSections> </li></ul><ul><li></chapter> </li></ul><ul><li><chapter> </li></ul><ul><li><chapterNo>4</chapterNo> </li></ul><ul><li><chapterTopic>Modular XSLT</chapterTopic> </li></ul><ul><li><chapterAuthor>Kurt Cagle</chapterAuthor> </li></ul><ul><li><chapterSections> </li></ul><ul><li><chapterSection>Section 1</chapterSection> </li></ul><ul><li><chapterSection>Section 2</chapterSection> </li></ul><ul><li><chapterSection>Section 3</chapterSection> </li></ul><ul><li><chapterSection>Section 4</chapterSection> </li></ul><ul><li><chapterSection>Section 5</chapterSection> </li></ul><ul><li><chapterSection>Section 6</chapterSection> </li></ul><ul><li></chapterSections> </li></ul><ul><li></chapter> </li></ul><ul><li></chapters> </li></ul><ul><li></book> </li></ul>
  89. 89. Basic XSL Example (apply0.xml) <ul><li><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version=&quot;1.0&quot;> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul><ul><li>What would be the output? </li></ul>
  90. 90. Explanation <ul><li>We have not specified what action should be taken when root is applied </li></ul><ul><li>This causes the entire output to be suppressed! </li></ul>
  91. 91. XSL Example: 1 (apply1.xsl) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul><ul><li>Output: ? </li></ul>
  92. 92. Explanation <ul><li>Now there is an <apply-templates> inside the <template match> </li></ul><ul><li>This causes the default <apply-templates> to be applied, i.e. without any particular select inside <apply-templates> </li></ul><ul><li>In other words, <apply-templates> gets executed for all elements inside the root </li></ul>
  93. 93. XSL Example: 2 (apply2.xsl) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;*&quot;> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  94. 94. Explanation <ul><li>Empty output, since <apply-templates/> will bring search from the root level to all non-root elements. </li></ul><ul><li>But at that level, there is no <apply-templates/> to display anything, unlike in the previous example. </li></ul>
  95. 95. XSL Example: 3 (apply3.xsl) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;*&quot;> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;book&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;chapters&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;chapter&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;chapterTopic&quot;> </li></ul><ul><li><!-- <xsl:apply-templates/> --> </li></ul><ul><li><xsl:value-of select=&quot;.&quot;/> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul><ul><li>Display the list of chapter topics </li></ul>
  96. 96. XSL Example: 4 (apply4.xsl) <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;*&quot;> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;book&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;chapters&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;chapter&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;/book/chapters/chapter/chapterNo&quot;> </li></ul><ul><li><xsl:value-of select=&quot;.&quot;/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;/book/chapters/chapter/chapterTopic&quot;> </li></ul><ul><li><xsl:value-of select=&quot;.&quot;/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;/book/chapters/chapter/chapterAuthor&quot;> </li></ul><ul><li><xsl:value-of select=&quot;.&quot;/> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul><ul><li>Display element values for all the selected elements </li></ul>
  97. 97. XSL Example: 6 (apply6.xsl) - Tricky <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; </li></ul><ul><li>xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  98. 98. XSL Example: 5 (apply5.xsl) – Tricky! <ul><li>What if we remove all search paths except the absolute ones? </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;/book/chapters/chapter/chapterNo&quot;> </li></ul><ul><li><xsl:value-of select=&quot;.&quot;/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;/book/chapters/chapter/chapterTopic&quot;> </li></ul><ul><li><xsl:value-of select=&quot;.&quot;/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;/book/chapters/chapter/chapterAuthor&quot;> </li></ul><ul><li><xsl:value-of select=&quot;.&quot;/> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  99. 99. Explanation <ul><li>Here, there is no <apply-templates> calling any of the defined <template match> tags </li></ul><ul><li>Hence, our <template match> tags would get ignored completely </li></ul><ul><li>Hence, it would produce the full XML contents as the output </li></ul>
  100. 100. Using the Mode Attribute
  101. 101. Using Mode <ul><li>If more than one template matches an identical pattern, a conflict arises </li></ul><ul><li>This can be solved by using template priority, but at times, that is also ambiguous </li></ul><ul><li>In such situations, we can use the template mode </li></ul><ul><li>Useful when a template needs to visit the same node, but with different results </li></ul>
  102. 102. Mode Example, also uses CSS <ul><li>XML (css-example-1) </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;css-example-1.xsl&quot;?> </li></ul><ul><li>< us > </li></ul><ul><li>< state name =&quot; Hawaii &quot;> </li></ul><ul><li>< county name =&quot; Hawaii &quot;> </li></ul><ul><li>< city class =&quot; largest &quot;> Hilo </ city > </li></ul><ul><li></ county > </li></ul><ul><li>< county name =&quot; Honolulu &quot;> </li></ul><ul><li>< city class =&quot; largest &quot;> Honolulu </ city > </li></ul><ul><li></ county > </li></ul><ul><li>< county name =&quot; Kauai &quot;> </li></ul><ul><li>< city class =&quot; largest &quot;> Kapaa </ city > </li></ul><ul><li></ county > </li></ul><ul><li>< county name =&quot; Maui &quot;> </li></ul><ul><li>< city class =&quot; largest &quot;> Kahului </ city > </li></ul><ul><li></ county > </li></ul><ul><li></ state > </li></ul><ul><li></ us > </li></ul><ul><li>XSL </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:output method =&quot; html &quot;/> </li></ul><ul><li>< xsl:template match =&quot; us/state &quot;> </li></ul><ul><li>< html > </li></ul><ul><li>< head > </li></ul><ul><li>< title > State: < xsl:value-of select =&quot; @name &quot;/> </li></ul><ul><li></ title > </li></ul><ul><li>< style type =&quot; text/css &quot;> </li></ul><ul><li>h1, h2 {font-family: sans-serif, color: blue} </li></ul><ul><li>ul {font-size: 16pt} </li></ul><ul><li></ style > </li></ul><ul><li></ head > </li></ul><ul><li>< body > </li></ul><ul><li>< h1 > State: < xsl:value-of select =&quot; @name &quot;/> </li></ul><ul><li></ h1 > </li></ul><ul><li>< h2 > All Countries </ h2 > </li></ul><ul><li>< ul > </li></ul><ul><li>< xsl:apply-templates select =&quot; county &quot; mode =&quot; county &quot;/> </li></ul><ul><li></ ul > </li></ul><ul><li>< h2 > Largest Cities (by County) </ h2 > </li></ul><ul><li>< ul > </li></ul><ul><li>< xsl:apply-templates select =&quot; county &quot; mode =&quot; city &quot;/> </li></ul><ul><li></ ul > </li></ul><ul><li></ body > </li></ul><ul><li></ html > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; county &quot; mode =&quot; county &quot;> </li></ul><ul><li>< li > </li></ul><ul><li>< xsl:value-of select =&quot; @name &quot;/> </li></ul><ul><li></ li > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; county &quot; mode =&quot; city &quot;> </li></ul><ul><li>< li > </li></ul><ul><li>< xsl:value-of select =&quot; city &quot;/> ( < xsl:value-of select =&quot; @name &quot;/> ) </li></ul><ul><li></ li > </li></ul><ul><li></ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul>
  103. 103. Creating New Elements and Attributes
  104. 104. Creating Elements and Attributes <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><students> </li></ul><ul><li><student first_name=&quot;Raju&quot;> </li></ul><ul><li><id>101</id> </li></ul><ul><li><remarks> A student who is not at all sincere!</remarks> </li></ul><ul><li></student> </li></ul><ul><li><student first_name=&quot;Aarati&quot;> </li></ul><ul><li><id>102</id> </li></ul><ul><li><remarks> A student who is really quite dedicated to her studies!</remarks> </li></ul><ul><li></student> </li></ul><ul><li><student first_name=&quot;Rajani&quot;> </li></ul><ul><li><id>103</id> </li></ul><ul><li><remarks> A student who is awesome!</remarks> </li></ul><ul><li></student> </li></ul><ul><li></students> </li></ul>
  105. 105. Corresponding XSL <ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;students&quot;> </li></ul><ul><li><students> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></students> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;student&quot;> </li></ul><ul><li><xsl:element name=&quot;{@first_name}&quot;> </li></ul><ul><li><xsl:attribute name=&quot;id&quot;><xsl:value-of select=&quot;id&quot;/></xsl:attribute> </li></ul><ul><li><notes> </li></ul><ul><li><xsl:value-of select=&quot;remarks&quot;/> </li></ul><ul><li></notes> </li></ul><ul><li></xsl:element> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  106. 106. Explanation - 1 <ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></xsl:template> </li></ul><ul><ul><li>match = “/” means select root </li></ul></ul><ul><ul><li><xsl:apply-templates/> means look for a “xsl:template match” at the root level; i.e. look for a definition that says <xsl:template match=“students&quot;> </li></ul></ul>
  107. 107. Explanation – 2 <ul><li><xsl:template match=&quot;students&quot;> </li></ul><ul><li><students> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></students> </li></ul><ul><li></xsl:template> </li></ul><ul><li>When the students element is found, output <students> </students> </li></ul><ul><li>Then look for a match inside < students> tag, i.e. for <student> tag now </li></ul>
  108. 108. Explanation – 3 <ul><li><xsl:template match=&quot;student&quot;> </li></ul><ul><li><xsl:element name=&quot;{@first_name}&quot;> </li></ul><ul><li><xsl:attribute name=&quot;id&quot;><xsl:value-of select=&quot;id&quot;/></xsl:attribute> </li></ul><ul><li><notes> </li></ul><ul><li><xsl:value-of select=&quot;remarks&quot;/> </li></ul><ul><li></notes> </li></ul><ul><li></xsl:element> </li></ul><ul><li></xsl:template> </li></ul><ul><li>When the < student> element is found, create a new element in the output XML whose element name equals the value of the attribute first_name in the input XML </li></ul><ul><li>So: </li></ul><ul><ul><li><student first_name=&quot;Raju&quot;> </li></ul></ul><ul><ul><li><id>101</id> </li></ul></ul><ul><ul><li><remarks> A student who is not at all sincere!</remarks> </li></ul></ul><ul><ul><li></student> </li></ul></ul><ul><li>Will now become </li></ul><ul><ul><li><Raju> </Raju> </li></ul></ul>
  109. 109. Explanation – 4 <ul><li><xsl:attribute name=&quot;id&quot;> </li></ul><ul><li><xsl:value-of select=&quot;id&quot;/> </li></ul><ul><li></xsl:attribute> </li></ul><ul><li>Add an attribute named id to the output XML, which equals the value of the element id of the input XML </li></ul>
  110. 110. Explanation – 5 <ul><li><notes> </li></ul><ul><li><xsl:value-of select=&quot;remarks&quot;/> </li></ul><ul><li></notes> </li></ul><ul><li>Add a new element called as notes to the output XML, which should contain the value of the remarks element of the input XML </li></ul>
  111. 111. Explanation – 6 <ul><li>Input XML </li></ul><ul><ul><li><student first_name=&quot;Raju&quot;> </li></ul></ul><ul><ul><li><id>101</id> </li></ul></ul><ul><ul><li><remarks> A student who is not at all sincere!</remarks> </li></ul></ul><ul><ul><li></student> </li></ul></ul><ul><li>Output XML </li></ul><ul><li><Raju id = “101”> </li></ul><ul><li><comments> A student who is not at all sincere!</comments> </li></ul><ul><li></Raju> </li></ul>
  112. 112. Running the Example <ul><li>set CLASSPATH=d:xalanbinxalan.jar;d:xalanbinxerces-Impl.jar </li></ul><ul><li>java org.apache.xalan.xslt.Process -INDENT 3 -IN three.xml -XSL three.xsl -OUT output.xml </li></ul>
  113. 113. Xalan and Xerces <ul><li>Xalan: Fully implements XSLT, XPath, and JAXP </li></ul><ul><li>Xerces: Implements XML specifications, namespaces, schema, SAX, DOM, and JAXP </li></ul>
  114. 114. Looping using for-each
  115. 115. Example: Change XML Contents into an HTML Table – XML File <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;cdcatalog.xsl&quot;?> </li></ul><ul><li><catalog> </li></ul><ul><li><cd> </li></ul><ul><li><title>Empire Burlesque</title> </li></ul><ul><li><artist>Bob Dylan</artist> </li></ul><ul><li><country>USA</country> </li></ul><ul><li><company>Columbia</company> </li></ul><ul><li><price>10.90</price> </li></ul><ul><li><year>1985</year> </li></ul><ul><li></cd> </li></ul><ul><li><cd> </li></ul><ul><li><title>Candle in the wind</title> </li></ul><ul><li><artist>Elton John</artist> </li></ul><ul><li><country>UK</country> </li></ul><ul><li><company>HMV</company> </li></ul><ul><li><price>8.20</price> </li></ul><ul><li><year>1998</year> </li></ul><ul><li></cd> </li></ul><ul><li></catalog> </li></ul>
  116. 116. Example: Change XML Contents into an HTML Table – XSL File <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; </li></ul><ul><li>xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><html> </li></ul><ul><li><body> </li></ul><ul><li><h2>My CD Collection</h2> </li></ul><ul><li><table border=&quot;1&quot;> </li></ul><ul><li><tr bgcolor=&quot;#9acd32&quot;> </li></ul><ul><li><th align=&quot;left&quot;>Title</th> </li></ul><ul><li><th align=&quot;left&quot;>Artist</th> </li></ul><ul><li></tr> </li></ul><ul><li><xsl:for-each select=&quot;catalog/cd&quot;> </li></ul><ul><li><tr> </li></ul><ul><li><td><xsl:value-of select=&quot;title&quot;/></td> </li></ul><ul><li><td><xsl:value-of select=&quot;artist&quot;/></td> </li></ul><ul><li></tr> </li></ul><ul><li></xsl:for-each> </li></ul><ul><li></table> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  117. 117. Exercise <ul><li>Display name, address, and phone number for all customers in a table </li></ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;foreach.xsl&quot; ?> </li></ul><ul><li><customers> </li></ul><ul><li><customer> </li></ul><ul><li><name>Mahesh Katare</name> </li></ul><ul><li><address>Eve's Plaza, Bangalore</address> </li></ul><ul><li><state>Karnataka</state> </li></ul><ul><li><phone>(80) 3247890</phone> </li></ul><ul><li></customer> </li></ul><ul><li><customer> </li></ul><ul><li><name>Naren Limaye</name> </li></ul><ul><li><address>Shanti Apartments, Thane</address> </li></ul><ul><li><state>Maharashtra</state> </li></ul><ul><li><phone>(22) 82791810</phone> </li></ul><ul><li></customer> </li></ul><ul><li><customer> </li></ul><ul><li><name>Uday Bhalerao</name> </li></ul><ul><li><address>Kothrud, Pune</address> </li></ul><ul><li><state>Maharashtra</state> </li></ul><ul><li><phone>(20) 25530834</phone> </li></ul><ul><li></customer> </li></ul><ul><li><customer> </li></ul><ul><li><name>Amol Kavthekar</name> </li></ul><ul><li><address>Station Road, Solapur</address> </li></ul><ul><li><state>Maharashtra</state> </li></ul><ul><li><phone>(217) 2729345</phone> </li></ul><ul><li></customer> </li></ul><ul><li><customer> </li></ul><ul><li><name>Meghraj Mane</name> </li></ul><ul><li><address>Cannuaght Place, Delhi</address> </li></ul><ul><li><state>Delhi</state> </li></ul><ul><li><phone>(11) 57814091</phone> </li></ul><ul><li></customer> </li></ul><ul><li><customer> </li></ul><ul><li><name>Sameer Joshi</name> </li></ul><ul><li><address>Gullapetti, Hyderabad</address> </li></ul><ul><li><state>Andhra Pradesh</state> </li></ul><ul><li><phone>93717-90911</phone> </li></ul><ul><li></customer> </li></ul><ul><li></customers> </li></ul>
  118. 118. Solution <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; </li></ul><ul><li>xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; > </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><HTML> </li></ul><ul><li><BODY> </li></ul><ul><li><TABLE border = &quot;2&quot;> </li></ul><ul><li><xsl:for-each select=&quot;customers/customer&quot;> </li></ul><ul><li><TR> </li></ul><ul><li><TD><xsl:value-of select=&quot;name&quot; /></TD> </li></ul><ul><li><TD><xsl:value-of select=&quot;address&quot; /></TD> </li></ul><ul><li><TD><xsl:value-of select=&quot;phone&quot; /></TD> </li></ul><ul><li></TR> </li></ul><ul><li></xsl:for-each> </li></ul><ul><li></TABLE> </li></ul><ul><li></BODY> </li></ul><ul><li></HTML> </li></ul><ul><li></xsl:template> </li></ul>
  119. 119. Exercise <ul><li>Achieve the same results without using for-each </li></ul>
  120. 120. Solution <ul><li><?xml version=&quot;1.0&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><HTML> </li></ul><ul><li><BODY> </li></ul><ul><li><TABLE border=&quot;2&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></TABLE> </li></ul><ul><li></BODY> </li></ul><ul><li></HTML> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;customers/customer&quot;> </li></ul><ul><li><TR> </li></ul><ul><li><TD> </li></ul><ul><li><xsl:value-of select=&quot;name&quot;/> </li></ul><ul><li></TD> </li></ul><ul><li><TD> </li></ul><ul><li><xsl:value-of select=&quot;address&quot;/> </li></ul><ul><li></TD> </li></ul><ul><li><TD> </li></ul><ul><li><xsl:value-of select=&quot;phone&quot;/> </li></ul><ul><li></TD> </li></ul><ul><li></TR> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  121. 121. Another for-each Example
  122. 122. Exercise: XML <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet href=&quot;SalesToHTML.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul><ul><li><SalesReport> </li></ul><ul><li><Company>i-flex Solutions Limited</Company> </li></ul><ul><li><Period>2005-06</Period> </li></ul><ul><li><Sales Region=&quot;US&quot;>USD 250 Million</Sales> </li></ul><ul><li><Sales Region=&quot;Europe&quot;>USD 100 Million</Sales> </li></ul><ul><li><Sales Region=&quot;Asia&quot;>USD 50 Million</Sales> </li></ul><ul><li></SalesReport> </li></ul>
  123. 123. Solution: XSL <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:output method=&quot;html&quot;/> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title>Sales Report, <xsl:value-of select=&quot;/SalesReport/Company&quot;/>: </li></ul><ul><li><xsl:value-of select=&quot;/SalesReport/Period&quot;/> </li></ul><ul><li></title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><br/> </li></ul><ul><li><h2> </li></ul><ul><li><xsl:value-of select=&quot;/SalesReport/Company&quot;/>, Sales Report: <xsl:value-of select=&quot;/SalesReport/Period&quot;/> </li></ul><ul><li></h2> </li></ul><ul><li><br/> </li></ul><ul><li><table width=&quot;50%&quot;> </li></ul><ul><li><tr> </li></ul><ul><li><th>Region</th> </li></ul><ul><li><th>Sales</th> </li></ul><ul><li></tr> </li></ul><ul><li><xsl:for-each select=&quot;/SalesReport/Sales&quot;> </li></ul><ul><li><tr> </li></ul><ul><li><td align=&quot;center&quot;> </li></ul><ul><li><xsl:value-of select=&quot;@Region&quot;/> </li></ul><ul><li></td> </li></ul><ul><li><td align=&quot;center&quot;> </li></ul><ul><li><xsl:value-of select=&quot;.&quot;/> </li></ul><ul><li></td> </li></ul><ul><li></tr> </li></ul><ul><li></xsl:for-each> </li></ul><ul><li></table> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  124. 124. Sorting Data
  125. 125. Sorting <ul><li>XML </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=&quot;test.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><xslTutorial> </li></ul></ul><ul><ul><li><name>John</name> </li></ul></ul><ul><ul><li><name>Josua</name> </li></ul></ul><ul><ul><li><name>Charles</name> </li></ul></ul><ul><ul><li><name>Alice</name> </li></ul></ul><ul><ul><li><name>Martha</name> </li></ul></ul><ul><ul><li><name>George</name> </li></ul></ul><ul><ul><li></xslTutorial> </li></ul></ul><ul><li>XSL </li></ul><ul><ul><li><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version=&quot;1.0&quot;> </li></ul></ul><ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul></ul><ul><ul><li><TABLE> </li></ul></ul><ul><ul><li><xsl:for-each select=&quot;//name&quot;> </li></ul></ul><ul><ul><li><xsl:sort order=&quot;ascending&quot; select=&quot;.&quot;/> </li></ul></ul><ul><ul><li><TR><TH><xsl:value-of select=&quot;.&quot;/></TH></TR> </li></ul></ul><ul><ul><li></xsl:for-each> </li></ul></ul><ul><ul><li></TABLE> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul>
  126. 126. Sorting Information <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; </li></ul><ul><li>xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul><ul><li><html> </li></ul><ul><li><body> </li></ul><ul><li><h2>My CD Collection</h2> </li></ul><ul><li><table border=&quot;1&quot;> </li></ul><ul><li><tr bgcolor=&quot;#9acd32&quot;> </li></ul><ul><li><th>Title</th> </li></ul><ul><li><th>Artist</th> </li></ul><ul><li></tr> </li></ul><ul><li><xsl:for-each select=&quot;catalog/cd&quot;> </li></ul><ul><li><xsl:sort select=&quot;artist&quot;/> </li></ul><ul><li><tr> </li></ul><ul><li><td><xsl:value-of select=&quot;title&quot;/></td> </li></ul><ul><li><td><xsl:value-of select=&quot;artist&quot;/></td> </li></ul><ul><li></tr> </li></ul><ul><li></xsl:for-each> </li></ul><ul><li></table> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li></xsl:template> </li></ul><ul><li></xsl:stylesheet> </li></ul>
  127. 127. Sorting – Another Example – XML File <ul><li><?xml version=&quot;1.0&quot; ?> </li></ul><ul><li><famous-persons> </li></ul><ul><li><persons category=&quot;medicine&quot;> </li></ul><ul><li><person> </li></ul><ul><li><firstname> Edward </firstname> </li></ul><ul><li><name> Jenner </name> </li></ul><ul><li></person> </li></ul><ul><li><person> </li></ul><ul><li><firstname> Gertrude </firstname> </li></ul><ul><li><name> Elion </name> </li></ul><ul><li></person> </li></ul><ul><li></persons> </li></ul><ul><li><persons category=&quot;computer science&quot;> </li></ul><ul><li><person> </li></ul><ul><li><firstname> Charles </firstname> </li></ul><ul><li><name> Babbage </name> </li></ul><ul><li></person> </li></ul><ul><li><person> </li></ul><ul><li><firstname> Alan </firstname> </li></ul><ul><li><name> Touring </name> </li></ul><ul><li></person> </li></ul><ul><li><person> </li></ul><ul><li><firstname> Ada </firstname> </li></ul><ul><li><name> Byron </name> </li></ul><ul><li></person> </li></ul><ul><li></persons> </li></ul><ul><li><persons category=&quot;astronomy&quot;> </li></ul><ul><li><person> </li></ul><ul><li><firstname> Tycho </firstname> </li></ul><ul><li><name> Brahe </name> </li></ul><ul><li></person> </li></ul><ul><li><person> </li></ul><ul><li><firstname> Johannes </firstname> </li></ul><ul><li><name> Kepler </name> </li></ul><ul><li></person> </li></ul><ul><li><person> </li></ul><ul><li><firstname> Galileo </firstname> </li></ul><ul><li><name> Galilei </name> </li></ul><ul><li></person> </li></ul><ul><li></persons> </li></ul><ul><li></famous-persons> </li></ul>
  128. 128. Sorting – Another Example – XSLT <ul><li>Write an XSLT for sorting data appropriately </li></ul>
  129. 129. Sorting and Data Types – 1 <ul><li>XML </li></ul><ul><ul><li><?xml version=&quot;1.0&quot;?> </li></ul></ul><ul><ul><li><?xml-stylesheet href=&quot;test.xsl&quot; type=&quot;text/xsl&quot;?> </li></ul></ul><ul><ul><li><xslTutorial > </li></ul></ul><ul><ul><li><car id=&quot;11&quot;/> </li></ul></ul><ul><ul><li><car id=&quot;6&quot;/> </li></ul></ul><ul><ul><li><car id=&quot;105&quot;/> </li></ul></ul><ul><ul><li><car id=&quot;28&quot;/> </li></ul></ul><ul><ul><li><car id=&quot;9&quot;/> </li></ul></ul><ul><ul><li></xslTutorial> </li></ul></ul><ul><li>XSL </li></ul><ul><ul><li><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version=&quot;1.0&quot;> </li></ul></ul><ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul></ul><ul><ul><li><TABLE> </li></ul></ul><ul><ul><li><xsl:for-each select=&quot;//car&quot;> </li></ul></ul><ul><ul><li><xsl:sort data-type=&quot;text&quot; select=&quot;@id&quot;/> </li></ul></ul><ul><ul><li><TR><TH><xsl:text> Car-</xsl:text> <xsl:value-of </li></ul></ul><ul><ul><li>select=&quot;@id&quot;/></TH></TR> </li></ul></ul><ul><ul><li></xsl:for-each> </li></ul></ul><ul><ul><li></TABLE> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul>
  130. 130. Sorting and Data Types – 2 <ul><li>Modified XSL </li></ul><ul><ul><li><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version=&quot;1.0&quot;> </li></ul></ul><ul><ul><li><xsl:template match=&quot;/&quot;> </li></ul></ul><ul><ul><li><TABLE> </li></ul></ul><ul><ul><li><xsl:for-each select=&quot;//car&quot;> </li></ul></ul><ul><ul><li><xsl:sort data-type=“number&quot; select=&quot;@id&quot;/> </li></ul></ul><ul><ul><li><TR><TH><xsl:text> Car-</xsl:text> <xsl:value-of </li></ul></ul><ul><ul><li>select=&quot;@id&quot;/></TH></TR> </li></ul></ul><ul><ul><li></xsl:for-each> </li></ul></ul><ul><ul><li></TABLE> </li></ul></ul><ul><ul><li></xsl:template> </li></ul></ul><ul><ul><li></xsl:stylesheet> </li></ul></ul>
  131. 131. Sorting on Multiple Keys <ul><li>Specify multiple xsl:sort elements, one after the other </li></ul><ul><li>Example </li></ul><ul><ul><li><xsl:sort select=“SURNAME”/> </li></ul></ul><ul><ul><li><xsl:sort select=“FIRSTNAME”/> </li></ul></ul><ul><ul><li><xsl:sort select=“BIRTH_DATE” order=“ascending”/> </li></ul></ul>
  132. 132. Another Sort Example <ul><li>sort-1.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;sort-1.xsl&quot;?> </li></ul><ul><li>< europe > </li></ul><ul><li>< state > Belgium </ state > </li></ul><ul><li>< state > Germany </ state > </li></ul><ul><li>< state > United Kingdom </ state > </li></ul><ul><li>< state > France </ state > </li></ul><ul><li>< state > Spain </ state > </li></ul><ul><li>< state > Italy </ state > </li></ul><ul><li>< state > Turkey </ state > </li></ul><ul><li>< state > Sweden </ state > </li></ul><ul><li>< state > Ireland </ state > </li></ul><ul><li>< state > Greece </ state > </li></ul><ul><li>< state > Malta </ state > </li></ul><ul><li>< state > Vatican City </ state > </li></ul><ul><li>< state > Portugal </ state > </li></ul><ul><li></ europe > </li></ul><ul><li>sort-1.xsl </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:template match =&quot; europe &quot;> </li></ul><ul><li>< xsl:text > Alphabetical List of European States </ xsl:text > </li></ul><ul><li>< xsl:text > Total Number of States: </ xsl:text > </li></ul><ul><li>< xsl:value-of select =&quot; count(state) &quot;/> </li></ul><ul><li>< xsl:text > </ xsl:text > </li></ul><ul><li>< xsl:apply-templates select =&quot; state &quot;> </li></ul><ul><li>< xsl:sort /> </li></ul><ul><li></ xsl:apply-templates > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; state &quot;> </li></ul><ul><li>< xsl:text > - </ xsl:text > </li></ul><ul><li>< xsl:apply-templates /> </li></ul><ul><li>< xsl:text > </ xsl:text > </li></ul><ul><li></ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul>
  133. 133. Producing HTML Output <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:output method =&quot; html &quot;/> </li></ul><ul><li>< xsl:template match =&quot; europe &quot;> </li></ul><ul><li>< html > </li></ul><ul><li>< head > </li></ul><ul><li>< title > European States </ title > </li></ul><ul><li></ head > </li></ul><ul><li>< style type =&quot; text/css &quot;> body {font-family: sans-serif} </ style > </li></ul><ul><li>< body > </li></ul><ul><li>< h3 > Alphabetical List of European States </ h3 > </li></ul><ul><li>< p > </li></ul><ul><li>< b > Total Number of States: </ b > </li></ul><ul><li>< xsl:value-of select =&quot; count(state) &quot;/> </li></ul><ul><li></ p > </li></ul><ul><li>< ul > </li></ul><ul><li>< xsl:apply-templates select =&quot; state &quot;> </li></ul><ul><li>< xsl:sort /> </li></ul><ul><li></ xsl:apply-templates > </li></ul><ul><li></ ul > </li></ul><ul><li></ body > </li></ul><ul><li></ html > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; state &quot;> </li></ul><ul><li>< li > </li></ul><ul><li>< xsl:apply-templates /> </li></ul><ul><li></ li > </li></ul><ul><li></ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul>
  134. 134. Output Using HTML Table <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> </li></ul><ul><li><xsl:output method=&quot;html&quot;/> </li></ul><ul><li><xsl:template match=&quot;europe&quot;> </li></ul><ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title>European States</title> </li></ul><ul><li></head> </li></ul><ul><li><style type=&quot;text/css&quot;>body {font-family: sans-serif}</style> </li></ul><ul><li><body> </li></ul><ul><li><h3>Alphabetical List of European States</h3> </li></ul><ul><li><p> </li></ul><ul><li><b>Total Number of States:</b> </li></ul><ul><li><xsl:value-of select=&quot;count(state)&quot;/> </li></ul><ul><li></p> </li></ul><ul><li><table border = &quot;3&quot; bgcolor = &quot;silver&quot;> </li></ul><ul><li><xsl:apply-templates select=&quot;state&quot;> </li></ul><ul><li><xsl:sort/> </li></ul><ul><li></xsl:apply-templates> </li></ul><ul><li></table> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li></xsl:template> </li></ul><ul><li><xsl:template match=&quot;state&quot;> </li></ul><ul><li><tr> </li></ul><ul><li><td style = &quot;color: blue&quot;> </li></ul><ul><li><xsl:apply-templates/> </li></ul><ul><li></td> </li></ul><ul><li></tr> </li></ul><ul><li></xsl:template> </li></ul>
  135. 135. Sorting on Attributes and Formatting <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:output method =&quot; text &quot;/> </li></ul><ul><li>< xsl:template match =&quot; europe &quot;> </li></ul><ul><li>< xsl:text > Number of EU Member States: </ xsl:text > </li></ul><ul><li>< xsl:value-of select =&quot; count(state) &quot;/> </li></ul><ul><li>< xsl:text > </ xsl:text > </li></ul><ul><li>< xsl:apply-templates select =&quot; state/@joined &quot;> </li></ul><ul><li>< xsl:sort data-type =&quot; number &quot;/> </li></ul><ul><li></ xsl:apply-templates > </li></ul><ul><li>< xsl:text > </ xsl:text > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; state/@joined &quot;> </li></ul><ul><li>< xsl:text > - </ xsl:text > </li></ul><ul><li>< xsl:apply-templates select =&quot; .. &quot;/> </li></ul><ul><li>< xsl:text > ( </ xsl:text > </li></ul><ul><li>< xsl:value-of select =&quot; . &quot;/> </li></ul><ul><li>< xsl:text > ) </ xsl:text > </li></ul><ul><li></ xsl:template > </li></ul><ul><li></ xsl:stylesheet > </li></ul>
  136. 136. Another Sort Example for Multiple Fields <ul><li>item-list.xml </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< list > </li></ul><ul><li>< freezer > </li></ul><ul><li>< item > peas </ item > </li></ul><ul><li>< item > green beans </ item > </li></ul><ul><li>< item > pot pie </ item > </li></ul><ul><li>< item > ice cream </ item > </li></ul><ul><li></ freezer > </li></ul><ul><li>< bakery > </li></ul><ul><li>< item > rolls </ item > </li></ul><ul><li>< item > jelly doughnuts </ item > </li></ul><ul><li>< item > bread </ item > </li></ul><ul><li></ bakery > </li></ul><ul><li>< produce > </li></ul><ul><li>< item > tomato </ item > </li></ul><ul><li>< item > apple </ item > </li></ul><ul><li>< item > potato </ item > </li></ul><ul><li></ produce > </li></ul><ul><li></ list > </li></ul><ul><li>item-list.xsl </li></ul><ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li>< xsl:stylesheet version =&quot; 1.0 &quot; xmlns:xsl =&quot; http://www.w3.org/1999/XSL/Transform &quot;> </li></ul><ul><li>< xsl:output method =&quot; text &quot; version =&quot; 1.0 &quot; encoding =&quot; UTF-8 &quot; indent =&quot; yes &quot;/> </li></ul><ul><li>< xsl:template match =&quot; list &quot;> </li></ul><ul><li>< xsl:apply-templates select =&quot; * &quot;> </li></ul><ul><li>< xsl:sort select =&quot; name() &quot;/> </li></ul><ul><li></ xsl:apply-templates > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:template match =&quot; * &quot;> </li></ul><ul><li>< xsl:text > Section: </ xsl:text > </li></ul><ul><li>< xsl:value-of select =&quot; name() &quot;/> </li></ul><ul><li>< xsl:text > </ xsl:text > </li></ul><ul><li>< xsl:apply-templates select =&quot; item &quot;> </li></ul><ul><li>< xsl:sort /> </li></ul><ul><li></ xsl:apply-templates > </li></ul><ul><li></ xsl:template > </li></ul><ul><li>< xsl:templat
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×