SlideShare a Scribd company logo
XSL , XSLT and XPATH
08/12/2015 1Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 XSL stands for EXtensible Stylesheet Language.
 It is an XML-based Stylesheet Language.
 XSL describes how the XML document should be displayed
 XSL consists of three parts:
 XSLT - a language for transforming XML documents
 XPath - a language for navigating inXML documents
 XSL-FO - a language for formatting XML documents
08/12/2015 2Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 XSLT stands for XSLTransformations,
 XSLT transforms an XML source-tree into an XML result-tree.
 XSLT transforms an XML document into another XML document,
recognized by a browser, like HTML and XHTML.
 Add/remove elements and attributes to or from the output file.
 Rearrange and sort elements, perform tests and make decisions about
which elements to hide and display, and a lot more.
 XSLT uses XPath to find information in an XML document.
 XPath is used to navigate through elements and attributes in XML
documents.
08/12/2015 3Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 How Does itWork?
 In the transformation process, XSLT uses XPath to define parts of the
source document that should match one or more predefined
templates.
 When a match is found, XSLT will transform the matching part of the
source document into the result document.
 All major browsers such as Internet Explorer ,Chrome, Firefox, Safari and
Opera supports XML, XSLT, and XPath
08/12/2015 4Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 The XML File
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
.
.
</catalog>
08/12/2015 5Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XSLT <xsl:stylesheet> Element
 defines that this document is an XSLT style sheet document (along with
the version number and XSLT namespace attributes).
XSLT <xsl:template> Element
 An XSL style sheet consists of one or more set of rules that are called
templates.
 A template contains rules to apply when a specified node is matched.
 The <xsl:template> element is used to build templates.
XSLT match attribute
 The match attribute is used to associate a template with an XML
element.
 The match attribute can also be used to define a template for the entire
XML document.
 The value of the match attribute is an XPath expression (i.e. match="/"
defines the whole document).
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
// some output
</xsl:template>
</xsl:stylesheet>08/12/2015 6Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XSLT <xsl:value-of> Element
 used to extract the value of an XML element and add it to the output
stream of the transformation
XSLT select attribute
 contains an XPath expression.An XPath expression works like navigating
a file system; a forward slash (/) selects subdirectories.
XSLT <xsl:for-each> and <xsl:sort> Element
 <xsl:for-each> element to loop through the XML elements, and display
all of the records.
 The <xsl:sort> element is used to sort the output.
 To sort the output, simply add an <xsl:sort> element inside the <xsl:for-
each> element in the XSL file:
 <xsl:for-each select="catalog/cd">
<xsl:sort select="artist"/>
<xsl:value-of select="title"/>
<xsl:value-of select="artist"/>
</xsl:for-each>
08/12/2015 7Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
The XML File
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
.
.
</catalog>
08/12/2015 8Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:sort select="artist"/>
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>08/12/2015 9Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XSLT <xsl:if> Element
 The <xsl:if> element is used to put a conditional test against the content of
the XML file.
 Syntax
<xsl:if test="expression">
...some output if the expression is true...
</xsl:if>
 To add a conditional test, add the <xsl:if> element inside the <xsl:for-each>
element in the XSL file.
 The value of the required test attribute contains the expression to be
evaluated.
08/12/2015 10Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:if test="price &gt; 10">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
08/12/2015 11Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XSLT <xsl:choose> Element
 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="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>
 To insert a multiple conditional test against the XML file, add the
<xsl:choose>, <xsl:when>, and <xsl:otherwise> elements to the XSL file:
08/12/2015 12Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price &gt; 10">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
08/12/2015 13Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XSLT <xsl:apply-templates> Element
 The <xsl:apply-templates> element applies a template to the current
element or it's child nodes.
 If we add a select attribute to the <xsl:apply-templates> element it will
process only the child element that matches the value of the select
attribute.
 We can use the select attribute to specify the order in which the child
nodes are processed.
 Some time XSL Style Sheet may have multiple matches
 <xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
08/12/2015 14Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XSLT <xsl:apply-templates> ElementCon…
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>MyCDCollection</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
<xsl:template match="title">
Title: <span style="color:#ff0000">
<xsl:value-of select="."/></span> // attribute to specify the current node
<br />
</xsl:template>
</xsl:stylesheet>
08/12/2015 15Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 XPath is a syntax for defining parts of an XML document
 XPath uses path expressions to navigate in XML documents
 XPath contains a library of standard functions
 XPath is also used in XSLT,XQuery, XPointer and XLink
 Without XPath knowledge you will not be able to create XSLT
documents.
 XPath is aW3C recommendation
08/12/2015 16Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
 there are various types of legal XPath expressions:
 Node sets-indicates what type of node you want to match
 Booleans-use the built-in XPath logical operators to produce Boolean
results.
Besides Boolean values, XPath can also work with node sets.
<xsl:template match="state[position() > 3]">
<xsl:value-of select="."/>
</xsl:template>
 Numbers- use numbers in expressions
<xsl:apply-templates select="state[population div area > 200]"/>
 Strings-XPath functions are specially designed to work on strings
 Wildcard - to select element nodes
 * -Matches any element node
 @*-Matches any attribute node
 node() -Matches any node of any kind
08/12/2015 17Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
08/12/2015 18Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
XPath Expression Result
/bookstore/book[1]
Selects the first book element that is the child of the bookstore
element
/bookstore/book[last()]
Selects the last book element that is the child of the bookstore
element
/bookstore/book[last()-1]
Selects the last but one book element that is the child of the
bookstore element
/bookstore/book[position()<3]
Selects the first two book elements that are children of the
bookstore element
//title[@lang] Selects all the title elements that have an attribute named lang
//title[@lang='eng']
Selects all the title elements that have an attribute named lang
with a value of 'eng'
/bookstore/book[price>35.00]
Selects all the book elements of the bookstore element that have a
price element with a value greater than 35.00
/bookstore/book[price>35.00]/title
Selects all the title elements of the book elements of the bookstore
element that have a price element with a value greater than 35.00
08/12/2015 19Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
Path Expression Result
//book/title | //book/price
Selects all the title AND price elements of all book
elements
//title | //price
Selects all the title AND price elements in the
document
/bookstore/book/title | //price
Selects all the title elements of the book element of the
bookstore element AND all the price elements in the
document
Path Expression Result
/bookstore/* Selects all the child nodes of the bookstore element
//* Selects all elements in the document
//title[@*] Selects all title elements which have any attribute
Example Result
child::book Selects all book nodes that are children of the current node
attribute::lang Selects the lang attribute of the current node
child::* Selects all element children of the current node
attribute::* Selects all attributes of the current node
child::text() Selects all text node children of the current node
child::node() Selects all children of the current node
descendant::book Selects all book descendants of the current node
ancestor::book Selects all book ancestors of the current node
ancestor-or-self::book
Selects all book ancestors of the current node - and the current as
well if it is a book node
child::*/child::price Selects all price grandchildren of the current node
08/12/2015 Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia 20
XPath Axes
 defines a node-set relative to the current node.
 XPath supports many different axes listed:
 ancestor — contains the ancestors of the context node. An
ancestor node is the parent of the context node,
the parent of the parent, and so forth, back to (and
including) the root node.
 ancestor-or-self — contains the context node and the ancestors
of the context node.
 Attribute — contains the attributes of the context node.
 Child — contains the children of the context node.
 Descendant — contains the descendants of the context node. A
descendant is a child or a child of a child and so on.
 descendant-or-self— contains the context node and the descendants of
the context node.
08/12/2015 Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia 21
XPath Axes Con…
 following — contains all nodes that come after the context
node.
 following-sibling — contains all the following siblings of the context
node.
 namespace — the namespace nodes of the
context node.
 parent — contains the parent of the context node.
 preceding — contains all nodes that come before the context
node.
 preceding-sibling — contains all the preceding siblings of the context
node.
 self — contains the context node.
08/12/2015 Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia 22
Node Sets
 By collecting nodes into a set, XPath lets you work with multiple nodes at
once
 Node set functions:
 last() — Returns the number of nodes in the node set.
 position() — Returns the position of the context node in the
node set. (The first node is Node 1.)
 count(node-set) — Returns the number of nodes in node-set.
 id(ID) — Returns a node set that contains the element
whose ID value matches ID.
 local-name(node-set) — Returns the name of the first node in node-set.
 namespace-uri (node-set) — Returns the URI of the namespace of the first
node in node-set.
 name(node-set) — Returns the qualified name of the first node in
node-set.
08/12/2015 Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia 23

More Related Content

What's hot

Protection and Security in Operating Systems
Protection and Security in Operating SystemsProtection and Security in Operating Systems
Protection and Security in Operating Systems
vampugani
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
Prof. Dr. K. Adisesha
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
BOSS Webtech
 
Command prompt presentation
Command prompt presentationCommand prompt presentation
Command prompt presentation
Muhammad Taj
 
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriyaIPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
VijiPriya Jeyamani
 
Internet programming lecture 1
Internet programming lecture 1Internet programming lecture 1
Internet programming lecture 1Mohammed Hussein
 
Introduction to Operating Systems
Introduction to Operating SystemsIntroduction to Operating Systems
Introduction to Operating Systems
Mukesh Chinta
 
14 relationship between processes
14 relationship between processes14 relationship between processes
14 relationship between processesmyrajendra
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
Prakhar Maurya
 
Android Components
Android ComponentsAndroid Components
Android Components
Aatul Palandurkar
 
Client server architecture
Client server architectureClient server architecture
Client server architecture
Bhargav Amin
 
Processes and threads
Processes and threadsProcesses and threads
Types Of Operating Systems
Types Of Operating SystemsTypes Of Operating Systems
Types Of Operating Systems
عطاءالمنعم اثیل شیخ
 
Css selectors
Css selectorsCss selectors
Css selectors
Parth Trivedi
 
Files in java
Files in javaFiles in java
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Network operating system
Network operating systemNetwork operating system
Network operating system
John Carlo Catacutan
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHP
Nicole Ryan
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
Haris Bin Zahid
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
teach4uin
 

What's hot (20)

Protection and Security in Operating Systems
Protection and Security in Operating SystemsProtection and Security in Operating Systems
Protection and Security in Operating Systems
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Command prompt presentation
Command prompt presentationCommand prompt presentation
Command prompt presentation
 
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriyaIPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
 
Internet programming lecture 1
Internet programming lecture 1Internet programming lecture 1
Internet programming lecture 1
 
Introduction to Operating Systems
Introduction to Operating SystemsIntroduction to Operating Systems
Introduction to Operating Systems
 
14 relationship between processes
14 relationship between processes14 relationship between processes
14 relationship between processes
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Android Components
Android ComponentsAndroid Components
Android Components
 
Client server architecture
Client server architectureClient server architecture
Client server architecture
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Types Of Operating Systems
Types Of Operating SystemsTypes Of Operating Systems
Types Of Operating Systems
 
Css selectors
Css selectorsCss selectors
Css selectors
 
Files in java
Files in javaFiles in java
Files in java
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Network operating system
Network operating systemNetwork operating system
Network operating system
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHP
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 

Viewers also liked

BAEB601 Chapter 1: Introduction To Research Methodology
BAEB601 Chapter 1: Introduction To Research MethodologyBAEB601 Chapter 1: Introduction To Research Methodology
BAEB601 Chapter 1: Introduction To Research MethodologyDr Nur Suhaili Ramli
 
Laptop repair speed
Laptop repair speedLaptop repair speed
Laptop repair speed
Kerry Prince
 
Training Presentation1
Training Presentation1Training Presentation1
Training Presentation1
elaruffa
 
Trouble shooting a computer
Trouble shooting a computerTrouble shooting a computer
Trouble shooting a computer
heidirobison
 
Motherboard Components
Motherboard ComponentsMotherboard Components
Motherboard Componentsstooty s
 
Introduction to Research Methodology
Introduction to Research MethodologyIntroduction to Research Methodology
Introduction to Research Methodology
Umm Al-Qura University Faculty of Dentistry
 
Motherboard and its components
Motherboard and its componentsMotherboard and its components
Motherboard and its components
Jishnu Pradeep
 
My research proposal.ppt
My research proposal.pptMy research proposal.ppt
My research proposal.pptnanimamat
 

Viewers also liked (8)

BAEB601 Chapter 1: Introduction To Research Methodology
BAEB601 Chapter 1: Introduction To Research MethodologyBAEB601 Chapter 1: Introduction To Research Methodology
BAEB601 Chapter 1: Introduction To Research Methodology
 
Laptop repair speed
Laptop repair speedLaptop repair speed
Laptop repair speed
 
Training Presentation1
Training Presentation1Training Presentation1
Training Presentation1
 
Trouble shooting a computer
Trouble shooting a computerTrouble shooting a computer
Trouble shooting a computer
 
Motherboard Components
Motherboard ComponentsMotherboard Components
Motherboard Components
 
Introduction to Research Methodology
Introduction to Research MethodologyIntroduction to Research Methodology
Introduction to Research Methodology
 
Motherboard and its components
Motherboard and its componentsMotherboard and its components
Motherboard and its components
 
My research proposal.ppt
My research proposal.pptMy research proposal.ppt
My research proposal.ppt
 

Similar to Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya

Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Allison Jai O'Dell
 
Session 4
Session 4Session 4
Xslt
XsltXslt
Xsl xslt
Xsl  xsltXsl  xslt
Xsl xslt
Dr.Saranya K.G
 
Introduction to XSLT
Introduction to XSLTIntroduction to XSLT
Introduction to XSLT
Mahmoud Allam
 
Xml transformation language
Xml transformation languageXml transformation language
Xml transformation languagereshmavasudev
 
transforming xml using xsl and xslt
transforming xml using xsl and xslttransforming xml using xsl and xslt
transforming xml using xsl and xslt
Hemant Suthar
 
Xslt
XsltXslt
XSL- XSLT.pdf
XSL- XSLT.pdfXSL- XSLT.pdf
XSL- XSLT.pdf
KGSCSEPSGCT
 
Overview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOOverview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOSuite Solutions
 
XPATH_XSLT-1.pptx
XPATH_XSLT-1.pptxXPATH_XSLT-1.pptx
XPATH_XSLT-1.pptx
BalasundaramSr
 
XSLT 3.0 Improvements - XML Prague 2018
XSLT 3.0 Improvements - XML Prague 2018XSLT 3.0 Improvements - XML Prague 2018
XSLT 3.0 Improvements - XML Prague 2018
Octavian Nadolu
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
Serhii Kartashov
 
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
SaraswathiRamalingam
 
"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides
Russell Ward
 
XSLT
XSLTXSLT
Xslt mule
Xslt   muleXslt   mule
Xslt mule
Sindhu VL
 
Xslt elements
Xslt elementsXslt elements
Xslt elements
Sindhu VL
 

Similar to Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya (20)

Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
Notes from the Library Juice Academy courses on XPath, XSLT, and XQuery: Univ...
 
Session 4
Session 4Session 4
Session 4
 
Xslt
XsltXslt
Xslt
 
Xslt
XsltXslt
Xslt
 
Xslt
XsltXslt
Xslt
 
Xsl xslt
Xsl  xsltXsl  xslt
Xsl xslt
 
Introduction to XSLT
Introduction to XSLTIntroduction to XSLT
Introduction to XSLT
 
Xml transformation language
Xml transformation languageXml transformation language
Xml transformation language
 
transforming xml using xsl and xslt
transforming xml using xsl and xslttransforming xml using xsl and xslt
transforming xml using xsl and xslt
 
Xslt
XsltXslt
Xslt
 
XSL- XSLT.pdf
XSL- XSLT.pdfXSL- XSLT.pdf
XSL- XSLT.pdf
 
Overview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOOverview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FO
 
XPATH_XSLT-1.pptx
XPATH_XSLT-1.pptxXPATH_XSLT-1.pptx
XPATH_XSLT-1.pptx
 
XSLT 3.0 Improvements - XML Prague 2018
XSLT 3.0 Improvements - XML Prague 2018XSLT 3.0 Improvements - XML Prague 2018
XSLT 3.0 Improvements - XML Prague 2018
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
 
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
 
"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides
 
XSLT
XSLTXSLT
XSLT
 
Xslt mule
Xslt   muleXslt   mule
Xslt mule
 
Xslt elements
Xslt elementsXslt elements
Xslt elements
 

More from VijiPriya Jeyamani

Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...
Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...
Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...
VijiPriya Jeyamani
 
Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...
Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...
Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...
VijiPriya Jeyamani
 
Dr. J. VijiPriya Information and Communication Technology Chapter 5,6
Dr. J. VijiPriya  Information and Communication Technology Chapter 5,6Dr. J. VijiPriya  Information and Communication Technology Chapter 5,6
Dr. J. VijiPriya Information and Communication Technology Chapter 5,6
VijiPriya Jeyamani
 
Human Computer Interaction Chapter 2 Interaction and Interaction Design Basi...
Human Computer Interaction Chapter 2  Interaction and Interaction Design Basi...Human Computer Interaction Chapter 2  Interaction and Interaction Design Basi...
Human Computer Interaction Chapter 2 Interaction and Interaction Design Basi...
VijiPriya Jeyamani
 
Human Computer Interaction Chapter 3 HCI in the Software Process and Design ...
Human Computer Interaction Chapter 3 HCI in the Software Process and  Design ...Human Computer Interaction Chapter 3 HCI in the Software Process and  Design ...
Human Computer Interaction Chapter 3 HCI in the Software Process and Design ...
VijiPriya Jeyamani
 
Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...
Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...
Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...
VijiPriya Jeyamani
 
Human Computer Interaction Chapter 5 Universal Design and User Support - Dr....
Human Computer Interaction Chapter 5 Universal Design and User Support -  Dr....Human Computer Interaction Chapter 5 Universal Design and User Support -  Dr....
Human Computer Interaction Chapter 5 Universal Design and User Support - Dr....
VijiPriya Jeyamani
 
Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya
 Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya
Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya
VijiPriya Jeyamani
 
CLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaCLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriya
VijiPriya Jeyamani
 
Information and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriya
Information and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriyaInformation and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriya
Information and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriya
VijiPriya Jeyamani
 
Integrative Programming Technology Chapter 5 - Dr. J. VijiPriya
Integrative Programming Technology Chapter 5 - Dr. J. VijiPriyaIntegrative Programming Technology Chapter 5 - Dr. J. VijiPriya
Integrative Programming Technology Chapter 5 - Dr. J. VijiPriya
VijiPriya Jeyamani
 

More from VijiPriya Jeyamani (11)

Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...
Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...
Dr. J. VijiPriya - Information and Communication Technology Chapter 8 The Int...
 
Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...
Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...
Dr. J. VijiPriya - Information Communication and Technology Chapter 7 Data Co...
 
Dr. J. VijiPriya Information and Communication Technology Chapter 5,6
Dr. J. VijiPriya  Information and Communication Technology Chapter 5,6Dr. J. VijiPriya  Information and Communication Technology Chapter 5,6
Dr. J. VijiPriya Information and Communication Technology Chapter 5,6
 
Human Computer Interaction Chapter 2 Interaction and Interaction Design Basi...
Human Computer Interaction Chapter 2  Interaction and Interaction Design Basi...Human Computer Interaction Chapter 2  Interaction and Interaction Design Basi...
Human Computer Interaction Chapter 2 Interaction and Interaction Design Basi...
 
Human Computer Interaction Chapter 3 HCI in the Software Process and Design ...
Human Computer Interaction Chapter 3 HCI in the Software Process and  Design ...Human Computer Interaction Chapter 3 HCI in the Software Process and  Design ...
Human Computer Interaction Chapter 3 HCI in the Software Process and Design ...
 
Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...
Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...
Human Computer Interaction Chapter 4 Implementation Support and Evaluation Te...
 
Human Computer Interaction Chapter 5 Universal Design and User Support - Dr....
Human Computer Interaction Chapter 5 Universal Design and User Support -  Dr....Human Computer Interaction Chapter 5 Universal Design and User Support -  Dr....
Human Computer Interaction Chapter 5 Universal Design and User Support - Dr....
 
Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya
 Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya
Expert System Lecture Notes Chapter 1,2,3,4,5 - Dr.J.VijiPriya
 
CLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriyaCLISP Lab Manual - Dr.J.VijiPriya
CLISP Lab Manual - Dr.J.VijiPriya
 
Information and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriya
Information and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriyaInformation and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriya
Information and Communication Technology Chapter 1,2 ,3 - Dr.J.VijiPriya
 
Integrative Programming Technology Chapter 5 - Dr. J. VijiPriya
Integrative Programming Technology Chapter 5 - Dr. J. VijiPriyaIntegrative Programming Technology Chapter 5 - Dr. J. VijiPriya
Integrative Programming Technology Chapter 5 - Dr. J. VijiPriya
 

Recently uploaded

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 

Recently uploaded (20)

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 

Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya

  • 1. XSL , XSLT and XPATH 08/12/2015 1Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 2.  XSL stands for EXtensible Stylesheet Language.  It is an XML-based Stylesheet Language.  XSL describes how the XML document should be displayed  XSL consists of three parts:  XSLT - a language for transforming XML documents  XPath - a language for navigating inXML documents  XSL-FO - a language for formatting XML documents 08/12/2015 2Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 3.  XSLT stands for XSLTransformations,  XSLT transforms an XML source-tree into an XML result-tree.  XSLT transforms an XML document into another XML document, recognized by a browser, like HTML and XHTML.  Add/remove elements and attributes to or from the output file.  Rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more.  XSLT uses XPath to find information in an XML document.  XPath is used to navigate through elements and attributes in XML documents. 08/12/2015 3Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 4.  How Does itWork?  In the transformation process, XSLT uses XPath to define parts of the source document that should match one or more predefined templates.  When a match is found, XSLT will transform the matching part of the source document into the result document.  All major browsers such as Internet Explorer ,Chrome, Firefox, Safari and Opera supports XML, XSLT, and XPath 08/12/2015 4Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 5.  The XML File <?xml version="1.0" encoding="UTF-8"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> . . </catalog> 08/12/2015 5Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 6. XSLT <xsl:stylesheet> Element  defines that this document is an XSLT style sheet document (along with the version number and XSLT namespace attributes). XSLT <xsl:template> Element  An XSL style sheet consists of one or more set of rules that are called templates.  A template contains rules to apply when a specified node is matched.  The <xsl:template> element is used to build templates. XSLT match attribute  The match attribute is used to associate a template with an XML element.  The match attribute can also be used to define a template for the entire XML document.  The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document). <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> // some output </xsl:template> </xsl:stylesheet>08/12/2015 6Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 7. XSLT <xsl:value-of> Element  used to extract the value of an XML element and add it to the output stream of the transformation XSLT select attribute  contains an XPath expression.An XPath expression works like navigating a file system; a forward slash (/) selects subdirectories. XSLT <xsl:for-each> and <xsl:sort> Element  <xsl:for-each> element to loop through the XML elements, and display all of the records.  The <xsl:sort> element is used to sort the output.  To sort the output, simply add an <xsl:sort> element inside the <xsl:for- each> element in the XSL file:  <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <xsl:value-of select="title"/> <xsl:value-of select="artist"/> </xsl:for-each> 08/12/2015 7Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 8. The XML File <?xml version="1.0" encoding="UTF-8"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> . . </catalog> 08/12/2015 8Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 9.  <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <xsl:sort select="artist"/> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>08/12/2015 9Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 10. XSLT <xsl:if> Element  The <xsl:if> element is used to put a conditional test against the content of the XML file.  Syntax <xsl:if test="expression"> ...some output if the expression is true... </xsl:if>  To add a conditional test, add the <xsl:if> element inside the <xsl:for-each> element in the XSL file.  The value of the required test attribute contains the expression to be evaluated. 08/12/2015 10Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 11.  <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <xsl:if test="price &gt; 10"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="artist"/></td> <td><xsl:value-of select="price"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> 08/12/2015 11Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 12. XSLT <xsl:choose> Element  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="expression"> ... some output ... </xsl:when> <xsl:otherwise> ... some output .... </xsl:otherwise> </xsl:choose>  To insert a multiple conditional test against the XML file, add the <xsl:choose>, <xsl:when>, and <xsl:otherwise> elements to the XSL file: 08/12/2015 12Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 13.  <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select="catalog/cd"> <tr> <td><xsl:value-of select="title"/></td> <xsl:choose> <xsl:when test="price &gt; 10"> <td bgcolor="#ff00ff"> <xsl:value-of select="artist"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="artist"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> 08/12/2015 13Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 14. XSLT <xsl:apply-templates> Element  The <xsl:apply-templates> element applies a template to the current element or it's child nodes.  If we add a select attribute to the <xsl:apply-templates> element it will process only the child element that matches the value of the select attribute.  We can use the select attribute to specify the order in which the child nodes are processed.  Some time XSL Style Sheet may have multiple matches  <xsl:template match="cd"> <p> <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/> </p> </xsl:template> 08/12/2015 14Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 15. XSLT <xsl:apply-templates> ElementCon… <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>MyCDCollection</h2> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="cd"> <p> <xsl:apply-templates select="title"/> <xsl:apply-templates select="artist"/> </p> </xsl:template> <xsl:template match="title"> Title: <span style="color:#ff0000"> <xsl:value-of select="."/></span> // attribute to specify the current node <br /> </xsl:template> </xsl:stylesheet> 08/12/2015 15Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 16.  XPath is a syntax for defining parts of an XML document  XPath uses path expressions to navigate in XML documents  XPath contains a library of standard functions  XPath is also used in XSLT,XQuery, XPointer and XLink  Without XPath knowledge you will not be able to create XSLT documents.  XPath is aW3C recommendation 08/12/2015 16Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 17.  there are various types of legal XPath expressions:  Node sets-indicates what type of node you want to match  Booleans-use the built-in XPath logical operators to produce Boolean results. Besides Boolean values, XPath can also work with node sets. <xsl:template match="state[position() > 3]"> <xsl:value-of select="."/> </xsl:template>  Numbers- use numbers in expressions <xsl:apply-templates select="state[population div area > 200]"/>  Strings-XPath functions are specially designed to work on strings  Wildcard - to select element nodes  * -Matches any element node  @*-Matches any attribute node  node() -Matches any node of any kind 08/12/2015 17Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia
  • 18. 08/12/2015 18Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia XPath Expression Result /bookstore/book[1] Selects the first book element that is the child of the bookstore element /bookstore/book[last()] Selects the last book element that is the child of the bookstore element /bookstore/book[last()-1] Selects the last but one book element that is the child of the bookstore element /bookstore/book[position()<3] Selects the first two book elements that are children of the bookstore element //title[@lang] Selects all the title elements that have an attribute named lang //title[@lang='eng'] Selects all the title elements that have an attribute named lang with a value of 'eng' /bookstore/book[price>35.00] Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00 /bookstore/book[price>35.00]/title Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00
  • 19. 08/12/2015 19Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia Path Expression Result //book/title | //book/price Selects all the title AND price elements of all book elements //title | //price Selects all the title AND price elements in the document /bookstore/book/title | //price Selects all the title elements of the book element of the bookstore element AND all the price elements in the document Path Expression Result /bookstore/* Selects all the child nodes of the bookstore element //* Selects all elements in the document //title[@*] Selects all title elements which have any attribute
  • 20. Example Result child::book Selects all book nodes that are children of the current node attribute::lang Selects the lang attribute of the current node child::* Selects all element children of the current node attribute::* Selects all attributes of the current node child::text() Selects all text node children of the current node child::node() Selects all children of the current node descendant::book Selects all book descendants of the current node ancestor::book Selects all book ancestors of the current node ancestor-or-self::book Selects all book ancestors of the current node - and the current as well if it is a book node child::*/child::price Selects all price grandchildren of the current node 08/12/2015 Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia 20
  • 21. XPath Axes  defines a node-set relative to the current node.  XPath supports many different axes listed:  ancestor — contains the ancestors of the context node. An ancestor node is the parent of the context node, the parent of the parent, and so forth, back to (and including) the root node.  ancestor-or-self — contains the context node and the ancestors of the context node.  Attribute — contains the attributes of the context node.  Child — contains the children of the context node.  Descendant — contains the descendants of the context node. A descendant is a child or a child of a child and so on.  descendant-or-self— contains the context node and the descendants of the context node. 08/12/2015 Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia 21
  • 22. XPath Axes Con…  following — contains all nodes that come after the context node.  following-sibling — contains all the following siblings of the context node.  namespace — the namespace nodes of the context node.  parent — contains the parent of the context node.  preceding — contains all nodes that come before the context node.  preceding-sibling — contains all the preceding siblings of the context node.  self — contains the context node. 08/12/2015 Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia 22
  • 23. Node Sets  By collecting nodes into a set, XPath lets you work with multiple nodes at once  Node set functions:  last() — Returns the number of nodes in the node set.  position() — Returns the position of the context node in the node set. (The first node is Node 1.)  count(node-set) — Returns the number of nodes in node-set.  id(ID) — Returns a node set that contains the element whose ID value matches ID.  local-name(node-set) — Returns the name of the first node in node-set.  namespace-uri (node-set) — Returns the URI of the namespace of the first node in node-set.  name(node-set) — Returns the qualified name of the first node in node-set. 08/12/2015 Dr. J.VijiPriya,Assistant Professor, Hawassa University, Ethiopia 23