SlideShare a Scribd company logo
1 of 15
Rajiv Poplai
Agenda
 Introduction to XSLT
 Examples
 Implementations
 XSLT processor
Warming up…
 What does XML stand for ?
 eXtensible Markup Language
 Extensible means that there is no fixed
tag set (like in HTML)
Overview
 Stands for “eXtensible Stylesheet
Language Transformations”
 Language for transforming an input xml
document into output document.
 Navigation of input XML document is
through XPath
 Output document may be XML or any other
text format.
XSLT processor
Language
 Syntax defined by W3C
 XSLT stylesheet file is an XML file
 XSLT is based on the programming
paradigm of pattern matching.
 XSLT is based on concepts of functional
programming as a stylesheet is made up of
templates, which are essentially pure
functions.
<xsl:stylesheet version=“1.0”
xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>
Simple Example
 Sample xml File
 Sample Output required in csv format
<?xml version=“1.0”?>
<ContactInfo>
<Person>
<Name>Rajiv Poplai</Name>
<Mobile>9810766277</Mobile>
</Person>
</ContactInfo>
Rajiv Poplai, 9810766277
 XSLT file to accomplish the
transformation
<?xml version=“1.0”?>
<xsl:stylesheet version=“1.0”
xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>
<xsl:output method=“text”>
<xsl:template match=“Person”>
<xsl:value-of select=“Name”/>
<xsl:text>,</xsl:text>
<xsl:value-of select=“Mobile”/>
</xsl:template>
</xsl:stylesheet>
<xsl:template> Element
 An xsl:template element essentially tells the
XSLT processor, “as you go through the
source tree, when you find a node of that tree
whose name matches the value of my match
attribute, add my contents to the result tree.”
<?xml version="1.0"?>
<ListOfStudents>
<?xml version="1.0"?>
<Students>
<Person id="12998800">
<FirstName>Peter</FirstName>
<LastName>Kováč</LastName>
<BirthDate>1980-10-25</BirthDate>
<Study>
<Program id="1.MAT"></Program>
<Faculty id="1070">FMFI UK</Faculty>
</Study>
<Study>
<Program id="1.AE"></Program>
<Faculty id="1050">FiF UK</Faculty>
</Study>
</Person>
<Person id="88332212">
<FirstName>Karol</FirstName>
<LastName>Nový</LastName>
<BirthDate>1982-11-16</BirthDate>
<Study>
<Program id="1.INF"></Program>
<Faculty id="1070">FMFI UK</Faculty>
</Study>
</Person>
</Students>
<?xml version="1.0"?>
<xsl:stylesheet version=“1.0"
xmlns:xsl="http://www.w3.org/1999
/XSL/Transform">
<xsl:template match="/">
<ListOfStudents>
<xsl:apply-templates/>
</ListOfStudents>
</xsl:template>
<xsl:template match="Person">
<Student>
<xsl:value-of
select="FirstName"/>,
<xsl:value-of
select="LastName"/>,
<xsl:value-of
select="Study[1]/Faculty"/>
(<xsl:value-of
select="Study[1]/Faculty/@id"/>)
</Student>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<ListOfStudents>
<Student>Peter, Kováč, FMFI UK (1070)</Student>
<Student>Karol, Nový, FMFI UK (1070)</Student>
</ListOfStudents>
Test your knowledge
 What would an XSLT processor do with a stylesheet that contained
no template rules?
 For example what would be the output if the stylesheet below:
 is applied to the XML file below
Answer
 XSLT has several built-in default templates that tell
the XSLT processor to output the text content of the
elements, leaving out the attributes and markup.
Other constructs
Tasks Construct (Instructions)
Creating new nodes <xsl:document>, <xsl:element>,
<xsl:attribute>, <xsl:text>, <xsl:value-of>
Iteration (process all nodes of a given
node set)
<xsl:for-each>
Conditional <xsl:if>, <xsl:choose>
Numbering <xsl:number>
Combining Stylesheets <xsl:include>, <xsl:import>
Sorting (sort a nodeset based on some
criteria)
<xsl:sort>
Variables <xsl:variable>, <xsl:param>
Invoking templates <xsl:apply-templates> (find a template
for each node in the input sequence)
<xsl:call-template>
Browser Support
Browser Minimum Version
Mozilla Firefox 3
Internet Explorer 6
Google Chrome 1
Opera 9
Apple Safari 3
Anatomy of XSLT processor

More Related Content

What's hot (19)

XSLT
XSLTXSLT
XSLT
 
XSLT and XPath - without the pain!
XSLT and XPath - without the pain!XSLT and XPath - without the pain!
XSLT and XPath - without the pain!
 
XML and XSLT
XML and XSLTXML and XSLT
XML and XSLT
 
Xslt by asfak mahamud
Xslt by asfak mahamudXslt by asfak mahamud
Xslt by asfak mahamud
 
XML XSLT
XML XSLTXML XSLT
XML XSLT
 
Querring xml with xpath
Querring xml with xpath Querring xml with xpath
Querring xml with xpath
 
Xslt
XsltXslt
Xslt
 
XSLT presentation
XSLT presentationXSLT presentation
XSLT presentation
 
5 xsl (formatting xml documents)
5   xsl (formatting xml documents)5   xsl (formatting xml documents)
5 xsl (formatting xml documents)
 
03 x files
03 x files03 x files
03 x files
 
Displaying XML Documents Using CSS and XSL
Displaying XML Documents Using CSS and XSLDisplaying XML Documents Using CSS and XSL
Displaying XML Documents Using CSS and XSL
 
XMLT
XMLTXMLT
XMLT
 
Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
 
Xml presentation
Xml presentationXml presentation
Xml presentation
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml schema
Xml schemaXml schema
Xml schema
 

Viewers also liked

Viewers also liked (19)

Xslt
XsltXslt
Xslt
 
XML and XPath details
XML and XPath detailsXML and XPath details
XML and XPath details
 
Jaxb
JaxbJaxb
Jaxb
 
Xml material
Xml materialXml material
Xml material
 
Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
Xpath presentation
Xpath presentationXpath presentation
Xpath presentation
 
Xpath
XpathXpath
Xpath
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
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
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Xml dom
Xml domXml dom
Xml dom
 
Dtd
DtdDtd
Dtd
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
The Mystical Principles of XSLT: Enlightenment through Software Visualization
The Mystical Principles of XSLT: Enlightenment through Software VisualizationThe Mystical Principles of XSLT: Enlightenment through Software Visualization
The Mystical Principles of XSLT: Enlightenment through Software Visualization
 
Unleashing the Power of XSLT: Catalog Records in Batch
Unleashing the Power of XSLT: Catalog Records in BatchUnleashing the Power of XSLT: Catalog Records in Batch
Unleashing the Power of XSLT: Catalog Records in Batch
 
Web Services
Web ServicesWeb Services
Web Services
 

Similar to XSLT

"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slidesRussell Ward
 
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriyaIntegrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriyaVijiPriya Jeyamani
 
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
 
Xml part5
Xml part5Xml part5
Xml part5NOHA AW
 
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriyaIPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriyaVijiPriya Jeyamani
 
XML - State of the Art
XML - State of the ArtXML - State of the Art
XML - State of the ArtJakub Malý
 
XML Support: Specifications and Development
XML Support: Specifications and DevelopmentXML Support: Specifications and Development
XML Support: Specifications and DevelopmentPeter Eisentraut
 
Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databasestorp42
 
Service Oriented Architecture- UNIT 2- XSL
Service Oriented Architecture- UNIT 2- XSLService Oriented Architecture- UNIT 2- XSL
Service Oriented Architecture- UNIT 2- XSLRoselin Mary S
 
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 BookNet Canada
 
CrashCourse: XML technologies
CrashCourse: XML technologiesCrashCourse: XML technologies
CrashCourse: XML technologiesESRI Bulgaria
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHPStephan Schmidt
 
Media IT - XML and XML Transformation (XSLT)
Media IT - XML and XML Transformation (XSLT)Media IT - XML and XML Transformation (XSLT)
Media IT - XML and XML Transformation (XSLT)Serge Linckels
 
Deep dive formatting
Deep dive formattingDeep dive formatting
Deep dive formattingThomas Lee
 

Similar to XSLT (20)

"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides"Getting Started with XSLT" presentation slides
"Getting Started with XSLT" presentation slides
 
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriyaIntegrative Programming and Technology Chapter 4- Dr. J. VijiPriya
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...
 
Xslt
XsltXslt
Xslt
 
Xml part5
Xml part5Xml part5
Xml part5
 
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriyaIPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
IPT Chapter 3 Data Mapping and Exchange - Dr. J. VijiPriya
 
XML - State of the Art
XML - State of the ArtXML - State of the Art
XML - State of the Art
 
XML Support: Specifications and Development
XML Support: Specifications and DevelopmentXML Support: Specifications and Development
XML Support: Specifications and Development
 
XSLT for Web Developers
XSLT for Web DevelopersXSLT for Web Developers
XSLT for Web Developers
 
Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databases
 
Service Oriented Architecture- UNIT 2- XSL
Service Oriented Architecture- UNIT 2- XSLService Oriented Architecture- UNIT 2- XSL
Service Oriented Architecture- UNIT 2- XSL
 
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
 
Xsl xslt
Xsl  xsltXsl  xslt
Xsl xslt
 
Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
 
CrashCourse: XML technologies
CrashCourse: XML technologiesCrashCourse: XML technologies
CrashCourse: XML technologies
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHP
 
Xml
XmlXml
Xml
 
Media IT - XML and XML Transformation (XSLT)
Media IT - XML and XML Transformation (XSLT)Media IT - XML and XML Transformation (XSLT)
Media IT - XML and XML Transformation (XSLT)
 
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
Unit 10: XML and Beyond (Sematic Web, Web Services, ...)
 
Deep dive formatting
Deep dive formattingDeep dive formatting
Deep dive formatting
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

XSLT

  • 2. Agenda  Introduction to XSLT  Examples  Implementations  XSLT processor
  • 3. Warming up…  What does XML stand for ?  eXtensible Markup Language  Extensible means that there is no fixed tag set (like in HTML)
  • 4. Overview  Stands for “eXtensible Stylesheet Language Transformations”  Language for transforming an input xml document into output document.  Navigation of input XML document is through XPath  Output document may be XML or any other text format.
  • 6. Language  Syntax defined by W3C  XSLT stylesheet file is an XML file  XSLT is based on the programming paradigm of pattern matching.  XSLT is based on concepts of functional programming as a stylesheet is made up of templates, which are essentially pure functions. <xsl:stylesheet version=“1.0” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>
  • 7. Simple Example  Sample xml File  Sample Output required in csv format <?xml version=“1.0”?> <ContactInfo> <Person> <Name>Rajiv Poplai</Name> <Mobile>9810766277</Mobile> </Person> </ContactInfo> Rajiv Poplai, 9810766277
  • 8.  XSLT file to accomplish the transformation <?xml version=“1.0”?> <xsl:stylesheet version=“1.0” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”> <xsl:output method=“text”> <xsl:template match=“Person”> <xsl:value-of select=“Name”/> <xsl:text>,</xsl:text> <xsl:value-of select=“Mobile”/> </xsl:template> </xsl:stylesheet>
  • 9. <xsl:template> Element  An xsl:template element essentially tells the XSLT processor, “as you go through the source tree, when you find a node of that tree whose name matches the value of my match attribute, add my contents to the result tree.”
  • 10. <?xml version="1.0"?> <ListOfStudents> <?xml version="1.0"?> <Students> <Person id="12998800"> <FirstName>Peter</FirstName> <LastName>Kováč</LastName> <BirthDate>1980-10-25</BirthDate> <Study> <Program id="1.MAT"></Program> <Faculty id="1070">FMFI UK</Faculty> </Study> <Study> <Program id="1.AE"></Program> <Faculty id="1050">FiF UK</Faculty> </Study> </Person> <Person id="88332212"> <FirstName>Karol</FirstName> <LastName>Nový</LastName> <BirthDate>1982-11-16</BirthDate> <Study> <Program id="1.INF"></Program> <Faculty id="1070">FMFI UK</Faculty> </Study> </Person> </Students> <?xml version="1.0"?> <xsl:stylesheet version=“1.0" xmlns:xsl="http://www.w3.org/1999 /XSL/Transform"> <xsl:template match="/"> <ListOfStudents> <xsl:apply-templates/> </ListOfStudents> </xsl:template> <xsl:template match="Person"> <Student> <xsl:value-of select="FirstName"/>, <xsl:value-of select="LastName"/>, <xsl:value-of select="Study[1]/Faculty"/> (<xsl:value-of select="Study[1]/Faculty/@id"/>) </Student> </xsl:template> </xsl:stylesheet> <?xml version="1.0"?> <ListOfStudents> <Student>Peter, Kováč, FMFI UK (1070)</Student> <Student>Karol, Nový, FMFI UK (1070)</Student> </ListOfStudents>
  • 11. Test your knowledge  What would an XSLT processor do with a stylesheet that contained no template rules?  For example what would be the output if the stylesheet below:  is applied to the XML file below
  • 12. Answer  XSLT has several built-in default templates that tell the XSLT processor to output the text content of the elements, leaving out the attributes and markup.
  • 13. Other constructs Tasks Construct (Instructions) Creating new nodes <xsl:document>, <xsl:element>, <xsl:attribute>, <xsl:text>, <xsl:value-of> Iteration (process all nodes of a given node set) <xsl:for-each> Conditional <xsl:if>, <xsl:choose> Numbering <xsl:number> Combining Stylesheets <xsl:include>, <xsl:import> Sorting (sort a nodeset based on some criteria) <xsl:sort> Variables <xsl:variable>, <xsl:param> Invoking templates <xsl:apply-templates> (find a template for each node in the input sequence) <xsl:call-template>
  • 14. Browser Support Browser Minimum Version Mozilla Firefox 3 Internet Explorer 6 Google Chrome 1 Opera 9 Apple Safari 3
  • 15. Anatomy of XSLT processor