SlideShare a Scribd company logo
1 of 43
XSL
• XSL stands for EXtensible Stylesheet
Language, and is a style sheet language
for XML documents.
• XSLT stands for XSL Transformations.
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.
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
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
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
XSL Architecture
Source
XML doc
XSL
stylesheet
XSL
processor
Target
Document
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
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">
cdcatalog.xml cdcatalog.xsl
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"
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
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.
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).
<?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
1cdcatalog.xml
1cdcatalog.xsl
View the result
2. XSLT <xsl:value-of> Element
• The <xsl:value-of> element is used to
extract the value of a selected node.
<?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
1cdcatalog.xml xsl value-of.xsl
View the Result
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:
<?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
1cdcatalog.xml XSL for-each.xsl
View the result
Filtering the Output
<xsl:for-each select="catalog/cd[artist='Bob Dylan']">
Legal filter operators are:
= (equal)
!= (not equal)
&lt; less than
&gt; greater than
<?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[artist='Bob Dylan']">
<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>
4. XSLT <xsl:sort> Element
• The <xsl:sort> element is used to sort the
output.
<?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
1cdcatalog.xml XSL sort.xsl
View the result
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>
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>
1cdcatalog.xml XSL:if.xsl
View the result
6. XSLT <xsl:choose> Element
• The <xsl:choose> element is used in
conjunction with <xsl:when> and
<xsl:otherwise> to express multiple
conditional tests.
The <xsl:choose> Element
Syntax
<xsl:choose>
<xsl:when test="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>
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:
<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
• 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
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.
<?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>
1cdcatalog.xml XSL:ApplyTemplates.xsl
View the result

More Related Content

What's hot (20)

WSDL
WSDLWSDL
WSDL
 
Xml schema
Xml schemaXml schema
Xml schema
 
Json
JsonJson
Json
 
Xpath presentation
Xpath presentationXpath presentation
Xpath presentation
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
Xml presentation
Xml presentationXml presentation
Xml presentation
 
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
 
Document Object Model (DOM)
Document Object Model (DOM)Document Object Model (DOM)
Document Object Model (DOM)
 
Xhtml
XhtmlXhtml
Xhtml
 
XSLT. Basic.
XSLT. Basic.XSLT. Basic.
XSLT. Basic.
 
Xml
XmlXml
Xml
 
Unit ii java script and xhtml documents and dynamic documents with javascript
Unit ii java script and xhtml documents and dynamic documents with javascriptUnit ii java script and xhtml documents and dynamic documents with javascript
Unit ii java script and xhtml documents and dynamic documents with javascript
 
Xpath.ppt
Xpath.pptXpath.ppt
Xpath.ppt
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
DTD
DTDDTD
DTD
 
Json
JsonJson
Json
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Json
JsonJson
Json
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 

Similar to XSLT.ppt (20)

Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
 
XSLT
XSLTXSLT
XSLT
 
Xslt
XsltXslt
Xslt
 
Xslt
XsltXslt
Xslt
 
Xml part5
Xml part5Xml part5
Xml part5
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLT
 
Xml
XmlXml
Xml
 
Service Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIService Oriented Architecture - Unit II
Service Oriented Architecture - Unit II
 
Xml and xslt
Xml and xsltXml and xslt
Xml and xslt
 
Xml 2
Xml  2 Xml  2
Xml 2
 
XSL- XSLT.pdf
XSL- XSLT.pdfXSL- XSLT.pdf
XSL- XSLT.pdf
 
Xsl xslt
Xsl  xsltXsl  xslt
Xsl xslt
 
Xslt
XsltXslt
Xslt
 
Service Oriented Architecture- UNIT 2- XSL
Service Oriented Architecture- UNIT 2- XSLService Oriented Architecture- UNIT 2- XSL
Service Oriented Architecture- UNIT 2- XSL
 
26xslt
26xslt26xslt
26xslt
 
XSLT for Web Developers
XSLT for Web DevelopersXSLT for Web Developers
XSLT for Web Developers
 
"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides
 
Introduction to XSLT
Introduction to XSLTIntroduction to XSLT
Introduction to XSLT
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 

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
 
XML-INTRODUCTION.pdf
XML-INTRODUCTION.pdfXML-INTRODUCTION.pdf
XML-INTRODUCTION.pdfKGSCSEPSGCT
 

More from KGSCSEPSGCT (11)

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
 
XML-INTRODUCTION.pdf
XML-INTRODUCTION.pdfXML-INTRODUCTION.pdf
XML-INTRODUCTION.pdf
 
2-DTD.ppt
2-DTD.ppt2-DTD.ppt
2-DTD.ppt
 
XML Schema.pdf
XML Schema.pdfXML Schema.pdf
XML Schema.pdf
 

Recently uploaded

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
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
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
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
 
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
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 

Recently uploaded (20)

Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
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
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
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
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
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...
 
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
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 

XSLT.ppt

  • 1. XSL
  • 2. • XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents. • XSLT stands for XSL Transformations.
  • 3. 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.
  • 4. 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
  • 5. 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
  • 6. 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
  • 8. 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
  • 9. 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">
  • 11. 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"
  • 12. 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
  • 13. 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.
  • 14. 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).
  • 15. <?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
  • 17. 2. XSLT <xsl:value-of> Element • The <xsl:value-of> element is used to extract the value of a selected node.
  • 18. <?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
  • 20. 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:
  • 21. <?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
  • 23. Filtering the Output <xsl:for-each select="catalog/cd[artist='Bob Dylan']"> Legal filter operators are: = (equal) != (not equal) &lt; less than &gt; greater than
  • 24. <?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[artist='Bob Dylan']"> <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>
  • 25.
  • 26. 4. XSLT <xsl:sort> Element • The <xsl:sort> element is used to sort the output.
  • 27. <?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
  • 28.
  • 30. 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>
  • 31. 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>
  • 32.
  • 34. 6. XSLT <xsl:choose> Element • The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests.
  • 35. The <xsl:choose> Element Syntax <xsl:choose> <xsl:when test="expression"> ... some output ... </xsl:when> <xsl:otherwise> ... some output .... </xsl:otherwise> </xsl:choose>
  • 36. 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:
  • 37. <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
  • 38. • 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
  • 39.
  • 40. 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.
  • 41. <?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>
  • 42.