SlideShare a Scribd company logo
Week 12 XML and XSL Revision :
XSLT (Extensible Stylesheet Language Transformations)  is a   declarative,   XML-based language used for the   transformation   of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one .
Overview The XSLT processing model involves: one or more XML  source  documents; one or more XSLT  stylesheet  modules; the XSLT template processing engine  the  processor ); and one or more  result  documents. The XSLT processor ordinarily takes two input documents -an XML source document, and an XSLT stylesheet—and produces an output document. The XSLT stylesheet contains a collection of  template rules :  instructions  and other directives that guide the processor in the production of the output document.
XSL Syntax revision You must include  <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?>  as the first line of code. (The encoding attribute is optional when using  XML Version 1.0)
You must then use the Correct Style Sheet Declaration The root  element  that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform> (The exact line below must be used) <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;>  The lines above do not  only declare that the document we have created is an  XSL  style sheet  but also that the  XSLT namespace  is being used which gives us access to the XSLT elements, attributes and features. (nothing in this line optional) The  xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;  points to the official W3C XSLT namespace.  If you use this namespace, you must also include the attribute version=&quot;1.0&quot;
Link the XSL Style Sheet to the XML Document To link a XSL style sheet reference to your XML document you just need to add the line underlined below to your XML document: <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;cdcatalog.xsl&quot;?> <catalog>  etc etc </catalog>
XSLT    Elements
The <xsl:template> Element The   match   attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match=&quot;/&quot; defines the whole document). Node Description/ attributes Example xsl:template Specifies processing templates “ match” is when the template should be used. “name” gives the template a name which xsl:call-templates etc can be use to call this template. <xsl:template match=&quot;/input&quot;> … </xsl:template>
The <xsl:value-of> Element The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation. The    value-of element often uses the select   attribute. The example from last week contains an XPath expression. An XPath expression works like navigating a file system; a forward slash (/) selects subdirectories This element generally uses the select attributes to specify the string to output. This element is self closing. <xsl:value-of select=&quot;catalog/cd/title&quot;/> Node Description/ attributes Example xsl:value-of The <xsl:value-of> element is used to extract the value of a selected node.   This element generally uses the select attributes to specify the string to output. This element is self closing. <xsl:value-of select=&quot;catalog/cd/title&quot;/>
The <xsl:for-each> Element The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set. It can be used    to loop through the XML elements, and display all of the records or specific records. The   select   attribute in the example from last week contains an XPath expression. An XPath expression works like navigating a file system; a forward slash (/) selects subdirectories. Filtering the Output We can also filter the output from the XML file by adding a criterion to the select attribute in the <xsl:for-each> element. Node Description/ attributes Example xsl:for-each Creates a loop which repeats for every match “ select” designates the match criteria Must be closed off <xsl:for-each  select=&quot;catalog/cd&quot; > … </xsl:for-each>
Filtering the Output We can also filter the output from the XML file by adding a criterion to the select attribute in the <xsl:for-each> element. <xsl:for-each select=&quot; catalog/cd[artist='Bob Dylan']&quot;> Legal filter operators are: =  (equal) != (not equal) &lt; less than &gt; greater than
Take a look at this modified example XSL style sheet: <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;>    <html>    <body>    <h2>My CD Collection</h2>    <table border=&quot;1&quot;>      <tr bgcolor=&quot;#9acd32&quot;>        <th>Title</th>        <th>Artist</th>      </tr>       <xsl:for-each select=&quot;catalog/cd[artist='Bob Dylan']&quot;>      <tr>        <td><xsl:value-of select=&quot;title&quot;/></td>        <td><xsl:value-of select=&quot;artist&quot;/></td>      </tr>       </xsl:for-each>    </table>    </body>    </html> </xsl:template> </xsl:stylesheet>
Exercise 2 Open your xml and xsl documents from last week and modify the xsl document so all teachers except me are displayed
XSLT   <xsl:sort>   Element The <xsl:sort> element is used to sort the output. Note:   It is possible for two conforming XSLT processors not to sort exactly the same Node Description/ attributes Example xsl:sort The sort element is used to sort the output by a particular element in ascending order. It can be a self contained element so there is no closing tag. It has the following attributes    order=&quot;ascending&quot; | &quot; descending&quot;  select=&quot;expression&quot; data-type=&quot;number&quot; &quot;qname&quot; | &quot;text Can be included inside the xsl:for-each and xsl:template elements <xsl:sort />
To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file:   <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;>    <html>    <body>    <h2>My CD Collection</h2>    <table border=&quot;1&quot;>      <tr bgcolor=&quot;#9acd32&quot;>        <th>Title</th>        <th>Artist</th>      </tr>      <xsl:for-each select=&quot;catalog/cd&quot;>         <xsl:sort select=&quot;artist&quot;/>        <tr>          <td><xsl:value-of select=&quot;title&quot;/></td>          <td><xsl:value-of select=&quot;artist&quot;/></td>        </tr>      </xsl:for-each>    </table>    </body>    </html> </xsl:template> </xsl:stylesheet>
Exercise 3 Open your xml and xsl documents from last week and modify the xsl document so the teachers are sorted by their first names in descending order
XSLT   <xsl:if>   Element To put a conditional if test against the content of the XML file, add an <xsl:if> element to the XSL document. Note:   The value of the required   test   attribute contains the expression to be evaluated Syntax <xsl:if test=&quot; expression &quot;>   ...some output if the expression is true... </xsl:if> Node Description/ attributes Example xsl:if Yes or No conditions “ test” specifies criteria for entering the if To add a conditional test, add the <xsl:if> element inside the <xsl:for-each> element in the XSL file: <xsl:if test=&quot;price &gt; 10&quot;> … </xsl:if>
Example <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;>   <html>   <body>   <h2>My CD Collection</h2>   <table border=&quot;1&quot;>     <tr bgcolor=&quot;#9acd32&quot;>       <th>Title</th>       <th>Artist</th>     </tr>     <xsl:for-each select=&quot;catalog/cd&quot;>        <xsl:if test=&quot;price &gt; 10&quot;>          <tr>           <td><xsl:value-of select=&quot;title&quot;/></td>           <td><xsl:value-of select=&quot;artist&quot;/></td>         </tr>        </xsl:if>      </xsl:for-each>   </table>   </body>   </html> </xsl:template> </stylesheet>
XSLT   <xsl:choose>   ,<xsl:when>  and <xsl:otherwise>  Elements The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests. Syntax <xsl:choose>   <xsl:when test=&quot; expression &quot;>     ... some output ...   </xsl:when>   <xsl:otherwise>     ... some output ....   </xsl:otherwise> </xsl:choose>
the   <xsl:choose>     Elements Node Description/ attributes Example xsl:choose Multiple choices No attributes <xsl:choose>   <xsl:when test=&quot; expression &quot;>     ... some output ...   </xsl:when>   <xsl:otherwise>     ... some output ....   </xsl:otherwise> </xsl:choose> xsl:when Yes or No conditions “ test” specifies criteria for entering the if <xsl:when test=&quot;$type='radio'&quot;> … </xsl:when> xsl:otherwise The default choice if none of the “xsl:when” criteria are met <xsl:otherwise> … </xsl:otherwise>
Where to put the Choose Condition To insert a multiple conditional test against the XML file, add the <xsl:choose>, <xsl:when>, and <xsl:otherwise> elements to the XSL file: Example <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;>   <html>   <body>   <h2>My CD Collection</h2>   <table border=&quot;1&quot;>     <tr bgcolor=&quot;#9acd32&quot;>       <th>Title</th>       <th>Artist</th>     </tr>     <xsl:for-each select=&quot;catalog/cd&quot;>     <tr>       <td><xsl:value-of select=&quot;title&quot;/></td>         <xsl:choose>          <xsl:when test=&quot;price &gt; 10&quot;>            <td bgcolor=&quot;#ff00ff&quot;>           <xsl:value-of select=&quot;artist&quot;/></td>           </xsl:when>          <xsl:otherwise>            <td><xsl:value-of select=&quot;artist&quot;/></td>          </xsl:otherwise>         </xsl:choose>      </tr>      </xsl:for-each>   </table>   </body>   </html> </xsl:template> </xsl:stylesheet>
Exercise 4 Open your xml and xsl documents from last week and modify the xsl document so that each teacher’s data is in a different colour

More Related Content

What's hot (20)

PPT
Xsd examples
Bình Trọng Án
 
PPT
02 xml schema
Baskarkncet
 
PPT
XSD
Kunal Gaind
 
PPTX
Introduction to xml
Gtu Booker
 
PPT
4 xml namespaces and xml schema
gauravashq
 
PPTX
Xml dtd
sana mateen
 
PPTX
XML Schema
Kumar
 
PPT
Xml 215-presentation
Manish Chaurasia
 
PPTX
XML Schemas
People Strategists
 
PDF
Introduction to DTD
torp42
 
PPTX
Xslt tutorial
Bijoy Kureekkal
 
PDF
Transforming xml with XSLT
Malintha Adikari
 
PPT
Xslt by asfak mahamud
Asfak Mahamud
 
PPTX
Xml basics
Kumar
 
PDF
XML Introduction
Marco Bresciani
 
PPT
3 xml namespaces and xml schema
gauravashq
 
PPTX
XSLT
rpoplai
 
PPT
Introduction to XML
BG Java EE Course
 
Xsd examples
Bình Trọng Án
 
02 xml schema
Baskarkncet
 
Introduction to xml
Gtu Booker
 
4 xml namespaces and xml schema
gauravashq
 
Xml dtd
sana mateen
 
XML Schema
Kumar
 
Xml 215-presentation
Manish Chaurasia
 
XML Schemas
People Strategists
 
Introduction to DTD
torp42
 
Xslt tutorial
Bijoy Kureekkal
 
Transforming xml with XSLT
Malintha Adikari
 
Xslt by asfak mahamud
Asfak Mahamud
 
Xml basics
Kumar
 
XML Introduction
Marco Bresciani
 
3 xml namespaces and xml schema
gauravashq
 
XSLT
rpoplai
 
Introduction to XML
BG Java EE Course
 

Viewers also liked (20)

PPTX
Meta tags
hapy
 
PPT
Assessment Validation IT Conference 08
hapy
 
PPT
Week 4 market segmentation
hapy
 
PPTX
Meta tags
hapy
 
PPT
Wikispaces Help
hapy
 
PPTX
Week1 xml
hapy
 
PPT
Meta tags1
hapy
 
PPTX
What is wordpress week 1
hapy
 
PDF
Week12 Obtain Client Sign Off On Technical Documentation
hapy
 
PPT
Week9 Define And Document Business Problems
hapy
 
PPT
Week4 Ensure Analysis Is Accurate And Complete
hapy
 
PPTX
2 understanding client support needs
hapy
 
PPT
Week11 Determine Technical Requirements
hapy
 
PPTX
1 understanding your clients
hapy
 
PPTX
3 proposing client support solutions
hapy
 
PPT
The Art Of Service Recovery
Barry Thierno
 
PPSX
The Profitable Art Of Service Recovery
Siddharth Anand
 
PPT
What is a service level agreement week7
hapy
 
PPT
Week7 Submit Analysis And Gain Agreement
hapy
 
PPT
Web 2 Tools
hapy
 
Meta tags
hapy
 
Assessment Validation IT Conference 08
hapy
 
Week 4 market segmentation
hapy
 
Meta tags
hapy
 
Wikispaces Help
hapy
 
Week1 xml
hapy
 
Meta tags1
hapy
 
What is wordpress week 1
hapy
 
Week12 Obtain Client Sign Off On Technical Documentation
hapy
 
Week9 Define And Document Business Problems
hapy
 
Week4 Ensure Analysis Is Accurate And Complete
hapy
 
2 understanding client support needs
hapy
 
Week11 Determine Technical Requirements
hapy
 
1 understanding your clients
hapy
 
3 proposing client support solutions
hapy
 
The Art Of Service Recovery
Barry Thierno
 
The Profitable Art Of Service Recovery
Siddharth Anand
 
What is a service level agreement week7
hapy
 
Week7 Submit Analysis And Gain Agreement
hapy
 
Web 2 Tools
hapy
 
Ad

Similar to Week 12 xml and xsl (20)

PPT
C:\fakepath\xsl final
shivpriya
 
PPTX
Xml part5
NOHA AW
 
PPT
Session 4
Lại Đức Chung
 
PPT
XSLT.ppt
KGSCSEPSGCT
 
PPTX
transforming xml using xsl and xslt
Hemant Suthar
 
PPT
Xml p5 Lecture Notes
Santhiya Grace
 
PPT
Rendering XML Document
yht4ever
 
PPTX
Xslt
Mahara Jothi
 
PPTX
XSLT
Surinder Kaur
 
PPT
Learning XSLT
Overdue Books LLC
 
PPT
Inroduction to XSLT with PHP4
Stephan Schmidt
 
PDF
XSL- XSLT.pdf
KGSCSEPSGCT
 
PPT
Xslt
Manav Prasad
 
PPTX
XSLT presentation
Miguel Angel Teheran Garcia
 
DOC
Xslt
prathap kumar
 
DOC
Xslt
xavier john
 
PDF
Xsl xslt
Dr.Saranya K.G
 
PPTX
XSLT
Kamal Acharya
 
PPT
Rendering XML Documents
yht4ever
 
PPTX
eXstensible Sylesheet Language_simple.pptx
AkshayKumar100378
 
C:\fakepath\xsl final
shivpriya
 
Xml part5
NOHA AW
 
XSLT.ppt
KGSCSEPSGCT
 
transforming xml using xsl and xslt
Hemant Suthar
 
Xml p5 Lecture Notes
Santhiya Grace
 
Rendering XML Document
yht4ever
 
Learning XSLT
Overdue Books LLC
 
Inroduction to XSLT with PHP4
Stephan Schmidt
 
XSL- XSLT.pdf
KGSCSEPSGCT
 
XSLT presentation
Miguel Angel Teheran Garcia
 
Xsl xslt
Dr.Saranya K.G
 
Rendering XML Documents
yht4ever
 
eXstensible Sylesheet Language_simple.pptx
AkshayKumar100378
 
Ad

More from hapy (6)

PPT
Business requirements documents
hapy
 
PPT
Information Architecture Intro
hapy
 
PPT
Week10 Analysing Client Requirements
hapy
 
PPT
Week8 Topic1 Translate Business Needs Into Technical Requirements
hapy
 
PPT
Week5 Ensure Analysis Is Accurate And Complete
hapy
 
PPT
JAD Workshops
hapy
 
Business requirements documents
hapy
 
Information Architecture Intro
hapy
 
Week10 Analysing Client Requirements
hapy
 
Week8 Topic1 Translate Business Needs Into Technical Requirements
hapy
 
Week5 Ensure Analysis Is Accurate And Complete
hapy
 
JAD Workshops
hapy
 

Recently uploaded (20)

PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Learn Computer Forensics, Second Edition
AnuraShantha7
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Learn Computer Forensics, Second Edition
AnuraShantha7
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 

Week 12 xml and xsl

  • 1. Week 12 XML and XSL Revision :
  • 2. XSLT (Extensible Stylesheet Language Transformations) is a   declarative,   XML-based language used for the   transformation   of XML documents. The original document is not changed; rather, a new document is created based on the content of an existing one .
  • 3. Overview The XSLT processing model involves: one or more XML  source  documents; one or more XSLT  stylesheet  modules; the XSLT template processing engine the  processor ); and one or more  result  documents. The XSLT processor ordinarily takes two input documents -an XML source document, and an XSLT stylesheet—and produces an output document. The XSLT stylesheet contains a collection of  template rules :  instructions  and other directives that guide the processor in the production of the output document.
  • 4. XSL Syntax revision You must include <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> as the first line of code. (The encoding attribute is optional when using XML Version 1.0)
  • 5. You must then use the Correct Style Sheet Declaration The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform> (The exact line below must be used) <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> The lines above do not only declare that the document we have created is an XSL style sheet but also that the XSLT namespace is being used which gives us access to the XSLT elements, attributes and features. (nothing in this line optional) The xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; points to the official W3C XSLT namespace. If you use this namespace, you must also include the attribute version=&quot;1.0&quot;
  • 6. Link the XSL Style Sheet to the XML Document To link a XSL style sheet reference to your XML document you just need to add the line underlined below to your XML document: <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;cdcatalog.xsl&quot;?> <catalog>  etc etc </catalog>
  • 8. The <xsl:template> Element The   match   attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match=&quot;/&quot; defines the whole document). Node Description/ attributes Example xsl:template Specifies processing templates “ match” is when the template should be used. “name” gives the template a name which xsl:call-templates etc can be use to call this template. <xsl:template match=&quot;/input&quot;> … </xsl:template>
  • 9. The <xsl:value-of> Element The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation. The   value-of element often uses the select   attribute. The example from last week contains an XPath expression. An XPath expression works like navigating a file system; a forward slash (/) selects subdirectories This element generally uses the select attributes to specify the string to output. This element is self closing. <xsl:value-of select=&quot;catalog/cd/title&quot;/> Node Description/ attributes Example xsl:value-of The <xsl:value-of> element is used to extract the value of a selected node. This element generally uses the select attributes to specify the string to output. This element is self closing. <xsl:value-of select=&quot;catalog/cd/title&quot;/>
  • 10. The <xsl:for-each> Element The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set. It can be used   to loop through the XML elements, and display all of the records or specific records. The   select   attribute in the example from last week contains an XPath expression. An XPath expression works like navigating a file system; a forward slash (/) selects subdirectories. Filtering the Output We can also filter the output from the XML file by adding a criterion to the select attribute in the <xsl:for-each> element. Node Description/ attributes Example xsl:for-each Creates a loop which repeats for every match “ select” designates the match criteria Must be closed off <xsl:for-each select=&quot;catalog/cd&quot; > … </xsl:for-each>
  • 11. Filtering the Output We can also filter the output from the XML file by adding a criterion to the select attribute in the <xsl:for-each> element. <xsl:for-each select=&quot; catalog/cd[artist='Bob Dylan']&quot;> Legal filter operators are: =  (equal) != (not equal) &lt; less than &gt; greater than
  • 12. Take a look at this modified example XSL style sheet: <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;>   <html>   <body>   <h2>My CD Collection</h2>   <table border=&quot;1&quot;>     <tr bgcolor=&quot;#9acd32&quot;>       <th>Title</th>       <th>Artist</th>     </tr>     <xsl:for-each select=&quot;catalog/cd[artist='Bob Dylan']&quot;>     <tr>       <td><xsl:value-of select=&quot;title&quot;/></td>       <td><xsl:value-of select=&quot;artist&quot;/></td>     </tr>     </xsl:for-each>   </table>   </body>   </html> </xsl:template> </xsl:stylesheet>
  • 13. Exercise 2 Open your xml and xsl documents from last week and modify the xsl document so all teachers except me are displayed
  • 14. XSLT   <xsl:sort>   Element The <xsl:sort> element is used to sort the output. Note:   It is possible for two conforming XSLT processors not to sort exactly the same Node Description/ attributes Example xsl:sort The sort element is used to sort the output by a particular element in ascending order. It can be a self contained element so there is no closing tag. It has the following attributes   order=&quot;ascending&quot; | &quot; descending&quot;  select=&quot;expression&quot; data-type=&quot;number&quot; &quot;qname&quot; | &quot;text Can be included inside the xsl:for-each and xsl:template elements <xsl:sort />
  • 15. To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file: <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;>   <html>   <body>   <h2>My CD Collection</h2>   <table border=&quot;1&quot;>     <tr bgcolor=&quot;#9acd32&quot;>       <th>Title</th>       <th>Artist</th>     </tr>     <xsl:for-each select=&quot;catalog/cd&quot;>       <xsl:sort select=&quot;artist&quot;/>       <tr>         <td><xsl:value-of select=&quot;title&quot;/></td>         <td><xsl:value-of select=&quot;artist&quot;/></td>       </tr>     </xsl:for-each>   </table>   </body>   </html> </xsl:template> </xsl:stylesheet>
  • 16. Exercise 3 Open your xml and xsl documents from last week and modify the xsl document so the teachers are sorted by their first names in descending order
  • 17. XSLT   <xsl:if>   Element To put a conditional if test against the content of the XML file, add an <xsl:if> element to the XSL document. Note:   The value of the required   test   attribute contains the expression to be evaluated Syntax <xsl:if test=&quot; expression &quot;>   ...some output if the expression is true... </xsl:if> Node Description/ attributes Example xsl:if Yes or No conditions “ test” specifies criteria for entering the if To add a conditional test, add the <xsl:if> element inside the <xsl:for-each> element in the XSL file: <xsl:if test=&quot;price &gt; 10&quot;> … </xsl:if>
  • 18. Example <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;>   <html>   <body>   <h2>My CD Collection</h2>   <table border=&quot;1&quot;>     <tr bgcolor=&quot;#9acd32&quot;>       <th>Title</th>       <th>Artist</th>     </tr>     <xsl:for-each select=&quot;catalog/cd&quot;>       <xsl:if test=&quot;price &gt; 10&quot;>         <tr>           <td><xsl:value-of select=&quot;title&quot;/></td>           <td><xsl:value-of select=&quot;artist&quot;/></td>         </tr>       </xsl:if>     </xsl:for-each>   </table>   </body>   </html> </xsl:template> </stylesheet>
  • 19. XSLT   <xsl:choose>   ,<xsl:when> and <xsl:otherwise> Elements The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests. Syntax <xsl:choose>   <xsl:when test=&quot; expression &quot;>     ... some output ...   </xsl:when>   <xsl:otherwise>     ... some output ....   </xsl:otherwise> </xsl:choose>
  • 20. the   <xsl:choose>   Elements Node Description/ attributes Example xsl:choose Multiple choices No attributes <xsl:choose>   <xsl:when test=&quot; expression &quot;>     ... some output ...   </xsl:when>   <xsl:otherwise>     ... some output ....   </xsl:otherwise> </xsl:choose> xsl:when Yes or No conditions “ test” specifies criteria for entering the if <xsl:when test=&quot;$type='radio'&quot;> … </xsl:when> xsl:otherwise The default choice if none of the “xsl:when” criteria are met <xsl:otherwise> … </xsl:otherwise>
  • 21. Where to put the Choose Condition To insert a multiple conditional test against the XML file, add the <xsl:choose>, <xsl:when>, and <xsl:otherwise> elements to the XSL file: Example <?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;/&quot;>   <html>   <body>   <h2>My CD Collection</h2>   <table border=&quot;1&quot;>     <tr bgcolor=&quot;#9acd32&quot;>       <th>Title</th>       <th>Artist</th>     </tr>     <xsl:for-each select=&quot;catalog/cd&quot;>     <tr>       <td><xsl:value-of select=&quot;title&quot;/></td>        <xsl:choose>         <xsl:when test=&quot;price &gt; 10&quot;>           <td bgcolor=&quot;#ff00ff&quot;>           <xsl:value-of select=&quot;artist&quot;/></td>         </xsl:when>         <xsl:otherwise>           <td><xsl:value-of select=&quot;artist&quot;/></td>         </xsl:otherwise>        </xsl:choose>     </tr>      </xsl:for-each>   </table>   </body>   </html> </xsl:template> </xsl:stylesheet>
  • 22. Exercise 4 Open your xml and xsl documents from last week and modify the xsl document so that each teacher’s data is in a different colour