SlideShare a Scribd company logo
1 of 20
Download to read offline
7/9/2019
Prepared By: Dr.Saranya.K.G 1
XSL
Prepared By : Dr.Saranya.K.G
• XSL stands for EXtensible Stylesheet
Language, and is a style sheet language
for XML documents.
• XSLT stands for XSL Transformations.
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 2
What is XSL?
• XSL is the style sheet language for XML
• Style sheets are typically used to specify
how information should be displayed.
• They lead to separation of document's
content from presentational information.
Prepared By : Dr.Saranya.K.G
XSL Languages
XSL consists of three parts:
• XSLT is a language for transforming
XML documents
• XPath is a language for defining parts of
an XML document
• XSL-FO is a language for formatting XML
documents
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 3
What is XSLT?
• XSLT is the most important part of XSL
• XSLT transforms an XML document
into another XML document
• XSLT uses XPath to navigate in XML
documents
• XSLT is a W3C Recommendation
Prepared By : Dr.Saranya.K.G
History
• XSL is derived from DSSSL
– Document Style and Semantics Specification
Language
• The style sheet language for SGML
• Based on the Scheme (Lisp) programming language
– XSL uses XML syntax instead of Scheme
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 4
XSL Architecture
Source
XML doc
XSL
stylesheet
XSL
processor
Target
Document
Prepared By : Dr.Saranya.K.G
XSL Use Scenarios
XML
document
XSL renderer
WWW browser
XML + f.o.
presentation
HTML
presentation
XSL
XSL
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 5
.xml
XSLT
Processor
.xsl
XSLT Stylesheet
XSLT Processor
.xml
XML Document
XML Document
Prepared By : Dr.Saranya.K.G
.xml
XSLT
Processor
.xsl
XSLT Stylesheet
XSLT Processor
XML Document
.html
HTML Document
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 6
XSL Use Scenarios
Application A Application B
XML format A XML format B
XSLT
A  B
stylesheets
Prepared By : Dr.Saranya.K.G
How does XSL work?
• The XSL processor parses the source
XML document
• Templates in the stylesheet are matched
against patterns in the source document
• The templates are expanded, producing
fragments of the target document
• This process is (typically) applied
recursively until all pattern-matches have
been exhausted
• The complete target document is
produced as output
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 7
XSLT - Transformation
• Correct Style Sheet Declaration
• The root element that declares the
document to be an XSL style sheet is
<xsl:stylesheet> or <xsl:transform>.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Or
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Prepared By : Dr.Saranya.K.G
cdcatalog.xml cdcatalog.xsl
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 8
Create an XSL Style Sheet
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
"cdcatalog.xsl"
Prepared By : Dr.Saranya.K.G
Link the XSL Style Sheet to the XML
Document
• Add the XSL style sheet reference to your XML
document ("cdcatalog.xml"):
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<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> View the result
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 9
1. 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.
Prepared By : Dr.Saranya.K.G
The <xsl:template> Element
• The <xsl:template> element is used to
build templates.
• 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).
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 10
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
<tr>
<td>.</td>
<td>.</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
1cdcatalog.xsl
Prepared By : Dr.Saranya.K.G
1cdcatalog.xml
1cdcatalog.xsl
View the result
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 11
2. XSLT <xsl:value-of> Element
• The <xsl:value-of> element is used to
extract the value of a selected node.
Prepared By : Dr.Saranya.K.G
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
<tr>
<td><xsl:value-of select="catalog/cd/title"/></td>
<td><xsl:value-of select="catalog/cd/artist"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
xsl value-of.xsl
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 12
1cdcatalog.xml xsl value-of.xsl
View the Result
Prepared By : Dr.Saranya.K.G
3. XSLT <xsl:for-each> Element
• The <xsl:for-each> element allows you to
do looping in XSLT.
• The XSL <xsl:for-each> element can be
used to select every XML element of a
specified node-set:
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 13
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XSL for-each.xsl
Prepared By : Dr.Saranya.K.G
1cdcatalog.xml XSL for-each.xsl
View the result
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 14
4. XSLT <xsl:sort> Element
• The <xsl:sort> element is used to sort the
output.
Prepared By : Dr.Saranya.K.G
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
XSL sort.xsl
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 15
1cdcatalog.xml XSL sort.xsl
View the result
Prepared By : Dr.Saranya.K.G
5. XSLT <xsl:if> Element
• The <xsl:if> element is used to put a conditional
test against the content of the XML file.
• To put a conditional if test against the content of
the XML file, add an <xsl:if> element to the XSL
document.
• Syntax
<xsl:if test="expression">
...some output if the expression is true...
</xsl:if> Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 16
Where to Put the <xsl:if> Element
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Prepared By : Dr.Saranya.K.G
1cdcatalog.xml XSL:if.xsl
View the result
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 17
6. XSLT <xsl:choose> Element
• The <xsl:choose> element is used in
conjunction with <xsl:when> and
<xsl:otherwise> to express multiple
conditional tests.
Prepared By : Dr.Saranya.K.G
The <xsl:choose> Element
Syntax
<xsl:choose>
<xsl:when test="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 18
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:
Prepared By : Dr.Saranya.K.G
<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 choose.xsl
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 19
• The code above will add a pink background-
color to the "Artist" column WHEN the price
of the CD is higher than 10.
1cdcatalog.xml XSL:choose.xsl
View the result
Prepared By : Dr.Saranya.K.G
XSLT <xsl:apply-templates>
Element
• The <xsl:apply-templates> element
applies a template to the current element
or to the current element's child nodes.
Prepared By : Dr.Saranya.K.G
7/9/2019
Prepared By: Dr.Saranya.K.G 20
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</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>
<br />
</xsl:template>
<xsl:template match="artist">
Artist: <span style="color:#00ff00">
<xsl:value-of select="."/></span>
<br />
</xsl:template>
</xsl:stylesheet>
Prepared By : Dr.Saranya.K.G
1cdcatalog.xml XSL:ApplyTemplates.xsl
View the result
Prepared By : Dr.Saranya.K.G

More Related Content

Similar to XSL- XSLT.pdf (20)

XSLT for Web Developers
XSLT for Web DevelopersXSLT for Web Developers
XSLT for Web Developers
 
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
 
XML XSLT
XML XSLTXML XSLT
XML XSLT
 
Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
 
Introduction to XSLT
Introduction to XSLTIntroduction to XSLT
Introduction to XSLT
 
XML Schema.pdf
XML Schema.pdfXML Schema.pdf
XML Schema.pdf
 
XSLT.ppt
XSLT.pptXSLT.ppt
XSLT.ppt
 
Service Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIService Oriented Architecture - Unit II
Service Oriented Architecture - Unit II
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml PPT
Xml PPTXml PPT
Xml PPT
 
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...
 
XSLT
XSLTXSLT
XSLT
 
Introduction of xml and xslt
Introduction of xml and xsltIntroduction of xml and xslt
Introduction of xml and xslt
 
XML/XSLT
XML/XSLTXML/XSLT
XML/XSLT
 
Xslt tutorial
Xslt tutorialXslt tutorial
Xslt tutorial
 
Session 4
Session 4Session 4
Session 4
 
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
 
XML-INTRODUCTION.pdf
XML-INTRODUCTION.pdfXML-INTRODUCTION.pdf
XML-INTRODUCTION.pdf
 
CTDA Workshop on XSL
CTDA Workshop on XSLCTDA Workshop on XSL
CTDA Workshop on XSL
 
Xml
XmlXml
Xml
 

More from KGSCSEPSGCT

Introduction to Distributed Systems
Introduction to Distributed SystemsIntroduction to Distributed Systems
Introduction to Distributed SystemsKGSCSEPSGCT
 
Unit4_Managing Contracts.ppt
Unit4_Managing Contracts.pptUnit4_Managing Contracts.ppt
Unit4_Managing Contracts.pptKGSCSEPSGCT
 
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.pptKGSCSEPSGCT
 
3-SchemaExamples.pdf
3-SchemaExamples.pdf3-SchemaExamples.pdf
3-SchemaExamples.pdfKGSCSEPSGCT
 
Converting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdfConverting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdfKGSCSEPSGCT
 

More from KGSCSEPSGCT (9)

Introduction to Distributed Systems
Introduction to Distributed SystemsIntroduction to Distributed Systems
Introduction to Distributed Systems
 
Unit4_Managing Contracts.ppt
Unit4_Managing Contracts.pptUnit4_Managing Contracts.ppt
Unit4_Managing Contracts.ppt
 
WSstandards.ppt
WSstandards.pptWSstandards.ppt
WSstandards.ppt
 
UDDI.ppt
UDDI.pptUDDI.ppt
UDDI.ppt
 
ROA.ppt
ROA.pptROA.ppt
ROA.ppt
 
REST Introduction.ppt
REST Introduction.pptREST Introduction.ppt
REST Introduction.ppt
 
3-SchemaExamples.pdf
3-SchemaExamples.pdf3-SchemaExamples.pdf
3-SchemaExamples.pdf
 
Converting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdfConverting DTDs to XML Schemas.pdf
Converting DTDs to XML Schemas.pdf
 
2-DTD.ppt
2-DTD.ppt2-DTD.ppt
2-DTD.ppt
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 

XSL- XSLT.pdf

  • 1. 7/9/2019 Prepared By: Dr.Saranya.K.G 1 XSL Prepared By : Dr.Saranya.K.G • XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents. • XSLT stands for XSL Transformations. Prepared By : Dr.Saranya.K.G
  • 2. 7/9/2019 Prepared By: Dr.Saranya.K.G 2 What is XSL? • XSL is the style sheet language for XML • Style sheets are typically used to specify how information should be displayed. • They lead to separation of document's content from presentational information. Prepared By : Dr.Saranya.K.G XSL Languages XSL consists of three parts: • XSLT is a language for transforming XML documents • XPath is a language for defining parts of an XML document • XSL-FO is a language for formatting XML documents Prepared By : Dr.Saranya.K.G
  • 3. 7/9/2019 Prepared By: Dr.Saranya.K.G 3 What is XSLT? • XSLT is the most important part of XSL • XSLT transforms an XML document into another XML document • XSLT uses XPath to navigate in XML documents • XSLT is a W3C Recommendation Prepared By : Dr.Saranya.K.G History • XSL is derived from DSSSL – Document Style and Semantics Specification Language • The style sheet language for SGML • Based on the Scheme (Lisp) programming language – XSL uses XML syntax instead of Scheme Prepared By : Dr.Saranya.K.G
  • 4. 7/9/2019 Prepared By: Dr.Saranya.K.G 4 XSL Architecture Source XML doc XSL stylesheet XSL processor Target Document Prepared By : Dr.Saranya.K.G XSL Use Scenarios XML document XSL renderer WWW browser XML + f.o. presentation HTML presentation XSL XSL Prepared By : Dr.Saranya.K.G
  • 5. 7/9/2019 Prepared By: Dr.Saranya.K.G 5 .xml XSLT Processor .xsl XSLT Stylesheet XSLT Processor .xml XML Document XML Document Prepared By : Dr.Saranya.K.G .xml XSLT Processor .xsl XSLT Stylesheet XSLT Processor XML Document .html HTML Document Prepared By : Dr.Saranya.K.G
  • 6. 7/9/2019 Prepared By: Dr.Saranya.K.G 6 XSL Use Scenarios Application A Application B XML format A XML format B XSLT A  B stylesheets Prepared By : Dr.Saranya.K.G How does XSL work? • The XSL processor parses the source XML document • Templates in the stylesheet are matched against patterns in the source document • The templates are expanded, producing fragments of the target document • This process is (typically) applied recursively until all pattern-matches have been exhausted • The complete target document is produced as output Prepared By : Dr.Saranya.K.G
  • 7. 7/9/2019 Prepared By: Dr.Saranya.K.G 7 XSLT - Transformation • Correct Style Sheet Declaration • The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform>. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> Or <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> Prepared By : Dr.Saranya.K.G cdcatalog.xml cdcatalog.xsl Prepared By : Dr.Saranya.K.G
  • 8. 7/9/2019 Prepared By: Dr.Saranya.K.G 8 Create an XSL Style Sheet <?xml version="1.0" encoding="ISO-8859-1"?> <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> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> "cdcatalog.xsl" Prepared By : Dr.Saranya.K.G Link the XSL Style Sheet to the XML Document • Add the XSL style sheet reference to your XML document ("cdcatalog.xml"): <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?> <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> View the result Prepared By : Dr.Saranya.K.G
  • 9. 7/9/2019 Prepared By: Dr.Saranya.K.G 9 1. 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. Prepared By : Dr.Saranya.K.G The <xsl:template> Element • The <xsl:template> element is used to build templates. • 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). Prepared By : Dr.Saranya.K.G
  • 10. 7/9/2019 Prepared By: Dr.Saranya.K.G 10 <?xml version="1.0" encoding="ISO-8859-1"?> <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> <tr> <td>.</td> <td>.</td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet> 1cdcatalog.xsl Prepared By : Dr.Saranya.K.G 1cdcatalog.xml 1cdcatalog.xsl View the result Prepared By : Dr.Saranya.K.G
  • 11. 7/9/2019 Prepared By: Dr.Saranya.K.G 11 2. XSLT <xsl:value-of> Element • The <xsl:value-of> element is used to extract the value of a selected node. Prepared By : Dr.Saranya.K.G <?xml version="1.0" encoding="ISO-8859-1"?> <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> <tr> <td><xsl:value-of select="catalog/cd/title"/></td> <td><xsl:value-of select="catalog/cd/artist"/></td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet> xsl value-of.xsl Prepared By : Dr.Saranya.K.G
  • 12. 7/9/2019 Prepared By: Dr.Saranya.K.G 12 1cdcatalog.xml xsl value-of.xsl View the Result Prepared By : Dr.Saranya.K.G 3. XSLT <xsl:for-each> Element • The <xsl:for-each> element allows you to do looping in XSLT. • The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set: Prepared By : Dr.Saranya.K.G
  • 13. 7/9/2019 Prepared By: Dr.Saranya.K.G 13 <?xml version="1.0" encoding="ISO-8859-1"?> <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> <td><xsl:value-of select="artist"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> XSL for-each.xsl Prepared By : Dr.Saranya.K.G 1cdcatalog.xml XSL for-each.xsl View the result Prepared By : Dr.Saranya.K.G
  • 14. 7/9/2019 Prepared By: Dr.Saranya.K.G 14 4. XSLT <xsl:sort> Element • The <xsl:sort> element is used to sort the output. Prepared By : Dr.Saranya.K.G <?xml version="1.0" encoding="ISO-8859-1"?> <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> XSL sort.xsl Prepared By : Dr.Saranya.K.G
  • 15. 7/9/2019 Prepared By: Dr.Saranya.K.G 15 1cdcatalog.xml XSL sort.xsl View the result Prepared By : Dr.Saranya.K.G 5. XSLT <xsl:if> Element • The <xsl:if> element is used to put a conditional test against the content of the XML file. • To put a conditional if test against the content of the XML file, add an <xsl:if> element to the XSL document. • Syntax <xsl:if test="expression"> ...some output if the expression is true... </xsl:if> Prepared By : Dr.Saranya.K.G
  • 16. 7/9/2019 Prepared By: Dr.Saranya.K.G 16 Where to Put the <xsl:if> Element <?xml version="1.0" encoding="ISO-8859-1"?> <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> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Prepared By : Dr.Saranya.K.G 1cdcatalog.xml XSL:if.xsl View the result Prepared By : Dr.Saranya.K.G
  • 17. 7/9/2019 Prepared By: Dr.Saranya.K.G 17 6. XSLT <xsl:choose> Element • The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests. Prepared By : Dr.Saranya.K.G The <xsl:choose> Element Syntax <xsl:choose> <xsl:when test="expression"> ... some output ... </xsl:when> <xsl:otherwise> ... some output .... </xsl:otherwise> </xsl:choose> Prepared By : Dr.Saranya.K.G
  • 18. 7/9/2019 Prepared By: Dr.Saranya.K.G 18 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: Prepared By : Dr.Saranya.K.G <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 choose.xsl Prepared By : Dr.Saranya.K.G
  • 19. 7/9/2019 Prepared By: Dr.Saranya.K.G 19 • The code above will add a pink background- color to the "Artist" column WHEN the price of the CD is higher than 10. 1cdcatalog.xml XSL:choose.xsl View the result Prepared By : Dr.Saranya.K.G XSLT <xsl:apply-templates> Element • The <xsl:apply-templates> element applies a template to the current element or to the current element's child nodes. Prepared By : Dr.Saranya.K.G
  • 20. 7/9/2019 Prepared By: Dr.Saranya.K.G 20 <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</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> <br /> </xsl:template> <xsl:template match="artist"> Artist: <span style="color:#00ff00"> <xsl:value-of select="."/></span> <br /> </xsl:template> </xsl:stylesheet> Prepared By : Dr.Saranya.K.G 1cdcatalog.xml XSL:ApplyTemplates.xsl View the result Prepared By : Dr.Saranya.K.G