SlideShare a Scribd company logo
Session 4 XSL – XSLT and More on XSLT Create by ChungLD faculty XML by Example / Bachkhoa – Aptech Computer Education /36
Objectives Introduction to XSL Working with XSL Xpath XPath Expressions and Functions Working with different styles Create by ChungLD faculty /36
Introduction to XSL Cascading  Style Sheet (CSS)  is a stylesheet technology that is used for HTML content formating. Extensible Stylesheet Language(XSL)  is developed by W3C to describe how the XML document should be displayed. XSL  is an XML-based language used to create stylesheets. XSL is designed to format XML content for display purposes and also has the ability to completely transform XML documents. Create by ChungLD faculty /36
Introduction to XSL… XSL consists of three languages: XSL Transformations (XSLT) – an XML language for transforming XML documemts. XML Path language (Xpath) – a language for navigating the XML document. XSL Formatting Object (XSL-FO) – an XML language for formatting XML documents. Create by ChungLD faculty /36 XSL XSLT XPath XSL-FO
XSL Transformations The transformation component of the XSL is XSLT. Its purpose is to transform XML documents. It describles the process of transforming an XML document, using a transform engine and XSL. The XML document and XSL stylesheet are provided as input to the XML transform engine, also known as the XSLT processor. Create by ChungLD faculty /36
What is XSLT? XSLT stands for XSL Transformations  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  Create by ChungLD faculty /36
XSL Transformations… Create by ChungLD faculty /36 Style Sheet XML  Source Document Result Document Transform process
XSL Processing Model The XML processor reads an XML document and processes it into a hierarchical tree containing nodes for each piece of information in document. After a document has been processe into a tree, the XSL processor begins applying the rules of an XSL stylesheet to the document tree. Create by ChungLD faculty /36
CSS and XSL XSL and CSS are two different style languages recommended by the W3C. XSL is more powerful and complex than CSS. Create by ChungLD faculty /36
XSLT Structure and Syntax In XSL, the style rules are written in a file with the extension .xsl. This file is associated with an XML document by using the statement :  <?xml-stylesheet href=“xsl file” type=“text/xsl”?> Create by ChungLD faculty /36
XSLT Structure and Syntax... XSLT structure file <xsl:stylesheet version=“1.0” xmlns:xsl= http://w3.org/1999/Transform > …… . </xsl:stylesheet> Where: <xsl:stylesheet>: Root element of the stylesheet xmlns:xsl= http://w3.org/1999/Transform : refers to the offical W3C XSLT namspace. You must include the attribute version=“1.0” if you use this namespace Create by ChungLD faculty /36
XSLT Structure and Syntax... Top Level XSLT Elements:  The top level XSLT elements can occur directly inside the xsl:stylesheet element. An element occurring as a child of an xsl:stylesheet element is called a top-level element. These elements provide the building blocks for creating XSLT documents Create by ChungLD faculty /36
The <xsl:template> Element A template is the main component of a stylesheet. Templates are defined with the helps of rules. The template rule is used to control the output of the XSLT processor. It defines the method by which an XML element node. A template rule consists of a pattern that indentifies the XML node and an action that selects and transforms the node. Each template rule is represented  by the <xsl:template> element. The <xsl: template> is an element that defines an action for producing output from a source document. Create by ChungLD faculty /36
Example the <xsl:template> Element Create by ChungLD faculty /36
The <xsl:template> Element… The match attribute in xsl:template is used to associate the template with an XML element. You can also define a template for a whole branch of the XML document by using the match attribute:  match=“/” Create by ChungLD faculty /36
XSL the <xsl:apply-template> element The xsl:apply-template element defines a set of nodes to be processed. This element, by default, selects all child nodes of the current node being processed, and finds a matching template rule to apply to each node in the set. Syntax: <xsl:templates match=“element”> <xsl:apply-templates select=“name of element”/> </xsl:templates> Where: select is an attribute can be used to process nodes selected by an expressiono instead f processing all children Create by ChungLD faculty /36 Click and see
The <xsl:value-of> Element The <xsl:value-of> element is used to extract the value of a selected node. Create by ChungLD faculty /36 Click and see
The xsl:text element The xls:text element is used to add literal text to the output. This element cannot contain any other XSL elements. It can contain only text. Syntax: <xsl:text disable-output-escaping=“yes” | “no”> text here </xsl:text> Where: if the value is no a literal “>” will appear as a “>” in the text Create by ChungLD faculty /36 Click and see
The <xsl:for-each> Element The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set: Create by ChungLD faculty /36 Click and see
The xsl:number element The xsl:number element is used to determin the sequence number for the current node. It can also be used to format a number for display in the output. <xsl:number count=“pattern” format=“{string}” value=“expression”> </xsl:number> Where:  count  is used indicates what nodes are to be counted. Only nodes that match the pattern are counted,  format  to be used for each number in the list,  value  specifies the expression to be converted to a number and output to the result tree. Create by ChungLD faculty /36 Click and see
The xsl:if element The xsl:if element evaluates a conditional expression against the content of the XML file. The test attribute of xsl:if element contains a conditional expression that evaluates to a boolean value of true of false. Syntax: <xsl:if test=“expression”> </xsl:if> Explain: the condition in the source data to test with either a true or false anwser. Create by ChungLD faculty /36 Click and see
The xsl:choose element The xsl:choose element is used to make a decision when there are two or moree possible course of action. The xsl:choose element is used in conjunction with xsl:when and xsl:otherwise to express multiple conditional tests. Syntax <xsl:choose> <xsl:when test=“expression”> template body </xsl:when> … . <xsl:otherwise> template body </xsl:otherwise> </xsl:choose> Create by ChungLD faculty /36 Click and see
The xsl:sort element in XSLT The xsl:sort element in XSLT can be used to sort a group of similar elements. The sorting can be done in various ways by using the attributes of this element. Syntax: <xsl:sort case-order=“upper-first” | “lower-first” data-type=“number” | “name” | “text” order=“ascending” | “descending” select=“expression”> </xsl:sort> Create by ChungLD faculty /36 Click and see
More on XSLT >>XPath XPath is a language for finding information in an XML document. XPath is a syntax for defining parts of an XML document  XPath uses path expressions to navigate in XML documents  XPath contains a library of standard functions  XPath is a major element in XSLT  XPath is a W3C recommendation  Create by ChungLD faculty /36
Benefits of Xpath XPath has many benefits, as follows: Syntax is simple for the simple and common cases. Any path that can occur in an XML document and any set of conditions for the nodes in the path can be specified. Any node in an XML document can be uniquely identified. Create by ChungLD faculty /36
XML document in XPath  In Xpath, an XML document is viewed conceptually as a tree in which each part of the document  is represented as a node. XPath have seven types of node: Root Element Attribute Text Comment Processing instruction Namespace Create by ChungLD faculty /36
XPath Representation An XPath query operates on a well-formed XML document after it has been parsed into a tree structure. <?xml version=“1.0”?> <!-- Fig. 11.1 :simple.xml --> <!– Simple XML document --> <book title=“C++ How to program “ edition=“3”> <sample> <![CDATA[  //C++ comment if(this->getX()<5 && value[0]!=3) cerr<<this->displayError(); ]]> </sample> C++ How to Program by Deitel &amp; Deitel </book> Create by ChungLD faculty /36 XPath Tree
Operators in XPath An XPath expression returns a note set, a boolean, a string, or a number. XPath provides basic floating point arithmetic operators and some comparision and boolean operators. Create by ChungLD faculty /36
Example of XPath operators Create by ChungLD faculty /36
XPath Expression XPath Expression are statements that can extract useful information from XPath tree. There are four types of expressions in XPath. They are: Node set Boolean Number String Create by ChungLD faculty /36
XPath Functions XPath defines various functions required for XPath 2.0, XQuery 1.0 and XSLT 2.0.  XPath functions can be used to refine XPath queries and enhance the programming power and flexibility of XPath. Create by ChungLD faculty /36
Node set Functions name(): return the name of the current node or the first node in the specified node set. local-name(): return the name of the current node or the first node in the specified node set without the namespace prefix. namespace-uri(): return the namespace URI of the current node or the first node in the specified node set. root(): return the root of tree text(): return the text of the current node Create by ChungLD faculty /36
Boolean Functions This functions can be used with comparison operators in filter patterns and return true or false. boolean(arg): returns a boolean value for a number, string, or node set. not(arg): reversed value of arg true(): return true false(): return false Create by ChungLD faculty /36
Numeric functions number(arg): return the numeric value of the arg ( arg could be a boolean, a string or a node set) ceiling(number) floor(number) round(number) Create by ChungLD faculty /36
String Functions string(arg) translate(string, string ,string) concat(string,string,…) substring(string, start, len) Create by ChungLD faculty /36
Transforming XML using XSLT The transformation of XML document can be done in various steps: Step 1 Start by creating a normal XML document <?xml version=“1.0” encoding=“utf-8”?> Step 2 Then add the lines shown below to create an XSL Stylesheet: <xsl:stylesheet xmlnx:xsl= http://www.w3.org/1999/xsl/transform  version=“1.0”> … .. </xsl:stylesheet> Step 3 Now, set it up to produce HTML – compatible ouput <xsl:stylesheet> <xsl:output method=“html”/> … . </xsl:stylesheet> Create by ChungLD faculty /36 XPath Tree
Summary and workshop Create by ChungLD faculty /36

More Related Content

PPTX
Html forms
Er. Nawaraj Bhandari
 
PPTX
Html frames
ManishaSheelam
 
PDF
Parse Tree
A. S. M. Shafi
 
PPT
b+ tree
bitistu
 
PPTX
XML Document Object Model (DOM)
BOSS Webtech
 
PPTX
Shadows Effects in CSS
Webtech Learning
 
PPTX
Angular js PPT
Imtiyaz Ahmad Khan
 
PPTX
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
Html frames
ManishaSheelam
 
Parse Tree
A. S. M. Shafi
 
b+ tree
bitistu
 
XML Document Object Model (DOM)
BOSS Webtech
 
Shadows Effects in CSS
Webtech Learning
 
Angular js PPT
Imtiyaz Ahmad Khan
 
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 

What's hot (20)

PPTX
XSLT
Kamal Acharya
 
PPTX
XSLT presentation
Miguel Angel Teheran Garcia
 
PPTX
Introduction to Javascript By Satyen
Satyen Pandya
 
PPTX
Non Deterministic and Deterministic Problems
Scandala Tamang
 
PPTX
Java script array
chauhankapil
 
PPTX
Html training slide
villupuramtraining
 
PPTX
Html 5-tables-forms-frames (1)
club23
 
PPTX
Popup boxes
sonal bisla
 
PDF
Introduction to CSS Grid Layout
Rachel Andrew
 
PPTX
Linked list
Md. Afif Al Mamun
 
PPTX
Css selectors
Parth Trivedi
 
PPTX
Quick Sort
Shweta Sahu
 
DOCX
SQL-RDBMS Queries and Question Bank
Md Mudassir
 
PPTX
HTML Text formatting tags
Himanshu Pathak
 
PPT
XML Schema
yht4ever
 
PDF
Sorting Algorithms
Mohammed Hussein
 
PDF
CSS Day: CSS Grid Layout
Rachel Andrew
 
PPT
Manipulation of Strings
Jancypriya M
 
XSLT presentation
Miguel Angel Teheran Garcia
 
Introduction to Javascript By Satyen
Satyen Pandya
 
Non Deterministic and Deterministic Problems
Scandala Tamang
 
Java script array
chauhankapil
 
Html training slide
villupuramtraining
 
Html 5-tables-forms-frames (1)
club23
 
Popup boxes
sonal bisla
 
Introduction to CSS Grid Layout
Rachel Andrew
 
Linked list
Md. Afif Al Mamun
 
Css selectors
Parth Trivedi
 
Quick Sort
Shweta Sahu
 
SQL-RDBMS Queries and Question Bank
Md Mudassir
 
HTML Text formatting tags
Himanshu Pathak
 
XML Schema
yht4ever
 
Sorting Algorithms
Mohammed Hussein
 
CSS Day: CSS Grid Layout
Rachel Andrew
 
Manipulation of Strings
Jancypriya M
 
Ad

Similar to Session 4 (20)

PPT
Learning XSLT
Overdue Books LLC
 
PPTX
XPATH_XSLT-1.pptx
BalasundaramSr
 
PPT
Xslt
Manav Prasad
 
PPTX
transforming xml using xsl and xslt
Hemant Suthar
 
PDF
XSLT and XPath - without the pain!
Bertrand Delacretaz
 
PPTX
XSLT - Extensible StyleSheet Language Transformations.pptx
abhishekoza1981
 
PDF
02_Xpath.pdf
Prerak10
 
DOC
Xslt
prathap kumar
 
DOC
Xslt
xavier john
 
PPTX
Xml part5
NOHA AW
 
PDF
Learning Xslt A Handson Introduction To Xslt And Xpath 1st Edition Michael Ja...
esgarkavos
 
PPT
Rendering XML Document
yht4ever
 
PPT
Rendering XML Documents
yht4ever
 
PDF
Xsl xslt
Dr.Saranya K.G
 
PPT
5 xsl (formatting xml documents)
gauravashq
 
PPTX
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
VijiPriya Jeyamani
 
PPT
Xslt by asfak mahamud
Asfak Mahamud
 
PPT
Xpath.ppt
Prerak10
 
PPT
Week 12 xml and xsl
hapy
 
Learning XSLT
Overdue Books LLC
 
XPATH_XSLT-1.pptx
BalasundaramSr
 
transforming xml using xsl and xslt
Hemant Suthar
 
XSLT and XPath - without the pain!
Bertrand Delacretaz
 
XSLT - Extensible StyleSheet Language Transformations.pptx
abhishekoza1981
 
02_Xpath.pdf
Prerak10
 
Xml part5
NOHA AW
 
Learning Xslt A Handson Introduction To Xslt And Xpath 1st Edition Michael Ja...
esgarkavos
 
Rendering XML Document
yht4ever
 
Rendering XML Documents
yht4ever
 
Xsl xslt
Dr.Saranya K.G
 
5 xsl (formatting xml documents)
gauravashq
 
Integrative Programming and Technology Chapter 4- Dr. J. VijiPriya
VijiPriya Jeyamani
 
Xslt by asfak mahamud
Asfak Mahamud
 
Xpath.ppt
Prerak10
 
Week 12 xml and xsl
hapy
 
Ad

Recently uploaded (20)

PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 

Session 4

  • 1. Session 4 XSL – XSLT and More on XSLT Create by ChungLD faculty XML by Example / Bachkhoa – Aptech Computer Education /36
  • 2. Objectives Introduction to XSL Working with XSL Xpath XPath Expressions and Functions Working with different styles Create by ChungLD faculty /36
  • 3. Introduction to XSL Cascading Style Sheet (CSS) is a stylesheet technology that is used for HTML content formating. Extensible Stylesheet Language(XSL) is developed by W3C to describe how the XML document should be displayed. XSL is an XML-based language used to create stylesheets. XSL is designed to format XML content for display purposes and also has the ability to completely transform XML documents. Create by ChungLD faculty /36
  • 4. Introduction to XSL… XSL consists of three languages: XSL Transformations (XSLT) – an XML language for transforming XML documemts. XML Path language (Xpath) – a language for navigating the XML document. XSL Formatting Object (XSL-FO) – an XML language for formatting XML documents. Create by ChungLD faculty /36 XSL XSLT XPath XSL-FO
  • 5. XSL Transformations The transformation component of the XSL is XSLT. Its purpose is to transform XML documents. It describles the process of transforming an XML document, using a transform engine and XSL. The XML document and XSL stylesheet are provided as input to the XML transform engine, also known as the XSLT processor. Create by ChungLD faculty /36
  • 6. What is XSLT? XSLT stands for XSL Transformations 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 Create by ChungLD faculty /36
  • 7. XSL Transformations… Create by ChungLD faculty /36 Style Sheet XML Source Document Result Document Transform process
  • 8. XSL Processing Model The XML processor reads an XML document and processes it into a hierarchical tree containing nodes for each piece of information in document. After a document has been processe into a tree, the XSL processor begins applying the rules of an XSL stylesheet to the document tree. Create by ChungLD faculty /36
  • 9. CSS and XSL XSL and CSS are two different style languages recommended by the W3C. XSL is more powerful and complex than CSS. Create by ChungLD faculty /36
  • 10. XSLT Structure and Syntax In XSL, the style rules are written in a file with the extension .xsl. This file is associated with an XML document by using the statement : <?xml-stylesheet href=“xsl file” type=“text/xsl”?> Create by ChungLD faculty /36
  • 11. XSLT Structure and Syntax... XSLT structure file <xsl:stylesheet version=“1.0” xmlns:xsl= http://w3.org/1999/Transform > …… . </xsl:stylesheet> Where: <xsl:stylesheet>: Root element of the stylesheet xmlns:xsl= http://w3.org/1999/Transform : refers to the offical W3C XSLT namspace. You must include the attribute version=“1.0” if you use this namespace Create by ChungLD faculty /36
  • 12. XSLT Structure and Syntax... Top Level XSLT Elements: The top level XSLT elements can occur directly inside the xsl:stylesheet element. An element occurring as a child of an xsl:stylesheet element is called a top-level element. These elements provide the building blocks for creating XSLT documents Create by ChungLD faculty /36
  • 13. The <xsl:template> Element A template is the main component of a stylesheet. Templates are defined with the helps of rules. The template rule is used to control the output of the XSLT processor. It defines the method by which an XML element node. A template rule consists of a pattern that indentifies the XML node and an action that selects and transforms the node. Each template rule is represented by the <xsl:template> element. The <xsl: template> is an element that defines an action for producing output from a source document. Create by ChungLD faculty /36
  • 14. Example the <xsl:template> Element Create by ChungLD faculty /36
  • 15. The <xsl:template> Element… The match attribute in xsl:template is used to associate the template with an XML element. You can also define a template for a whole branch of the XML document by using the match attribute: match=“/” Create by ChungLD faculty /36
  • 16. XSL the <xsl:apply-template> element The xsl:apply-template element defines a set of nodes to be processed. This element, by default, selects all child nodes of the current node being processed, and finds a matching template rule to apply to each node in the set. Syntax: <xsl:templates match=“element”> <xsl:apply-templates select=“name of element”/> </xsl:templates> Where: select is an attribute can be used to process nodes selected by an expressiono instead f processing all children Create by ChungLD faculty /36 Click and see
  • 17. The <xsl:value-of> Element The <xsl:value-of> element is used to extract the value of a selected node. Create by ChungLD faculty /36 Click and see
  • 18. The xsl:text element The xls:text element is used to add literal text to the output. This element cannot contain any other XSL elements. It can contain only text. Syntax: <xsl:text disable-output-escaping=“yes” | “no”> text here </xsl:text> Where: if the value is no a literal “>” will appear as a “>” in the text Create by ChungLD faculty /36 Click and see
  • 19. The <xsl:for-each> Element The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set: Create by ChungLD faculty /36 Click and see
  • 20. The xsl:number element The xsl:number element is used to determin the sequence number for the current node. It can also be used to format a number for display in the output. <xsl:number count=“pattern” format=“{string}” value=“expression”> </xsl:number> Where: count is used indicates what nodes are to be counted. Only nodes that match the pattern are counted, format to be used for each number in the list, value specifies the expression to be converted to a number and output to the result tree. Create by ChungLD faculty /36 Click and see
  • 21. The xsl:if element The xsl:if element evaluates a conditional expression against the content of the XML file. The test attribute of xsl:if element contains a conditional expression that evaluates to a boolean value of true of false. Syntax: <xsl:if test=“expression”> </xsl:if> Explain: the condition in the source data to test with either a true or false anwser. Create by ChungLD faculty /36 Click and see
  • 22. The xsl:choose element The xsl:choose element is used to make a decision when there are two or moree possible course of action. The xsl:choose element is used in conjunction with xsl:when and xsl:otherwise to express multiple conditional tests. Syntax <xsl:choose> <xsl:when test=“expression”> template body </xsl:when> … . <xsl:otherwise> template body </xsl:otherwise> </xsl:choose> Create by ChungLD faculty /36 Click and see
  • 23. The xsl:sort element in XSLT The xsl:sort element in XSLT can be used to sort a group of similar elements. The sorting can be done in various ways by using the attributes of this element. Syntax: <xsl:sort case-order=“upper-first” | “lower-first” data-type=“number” | “name” | “text” order=“ascending” | “descending” select=“expression”> </xsl:sort> Create by ChungLD faculty /36 Click and see
  • 24. More on XSLT >>XPath XPath is a language for finding information in an XML document. XPath is a syntax for defining parts of an XML document XPath uses path expressions to navigate in XML documents XPath contains a library of standard functions XPath is a major element in XSLT XPath is a W3C recommendation Create by ChungLD faculty /36
  • 25. Benefits of Xpath XPath has many benefits, as follows: Syntax is simple for the simple and common cases. Any path that can occur in an XML document and any set of conditions for the nodes in the path can be specified. Any node in an XML document can be uniquely identified. Create by ChungLD faculty /36
  • 26. XML document in XPath In Xpath, an XML document is viewed conceptually as a tree in which each part of the document is represented as a node. XPath have seven types of node: Root Element Attribute Text Comment Processing instruction Namespace Create by ChungLD faculty /36
  • 27. XPath Representation An XPath query operates on a well-formed XML document after it has been parsed into a tree structure. <?xml version=“1.0”?> <!-- Fig. 11.1 :simple.xml --> <!– Simple XML document --> <book title=“C++ How to program “ edition=“3”> <sample> <![CDATA[ //C++ comment if(this->getX()<5 && value[0]!=3) cerr<<this->displayError(); ]]> </sample> C++ How to Program by Deitel &amp; Deitel </book> Create by ChungLD faculty /36 XPath Tree
  • 28. Operators in XPath An XPath expression returns a note set, a boolean, a string, or a number. XPath provides basic floating point arithmetic operators and some comparision and boolean operators. Create by ChungLD faculty /36
  • 29. Example of XPath operators Create by ChungLD faculty /36
  • 30. XPath Expression XPath Expression are statements that can extract useful information from XPath tree. There are four types of expressions in XPath. They are: Node set Boolean Number String Create by ChungLD faculty /36
  • 31. XPath Functions XPath defines various functions required for XPath 2.0, XQuery 1.0 and XSLT 2.0. XPath functions can be used to refine XPath queries and enhance the programming power and flexibility of XPath. Create by ChungLD faculty /36
  • 32. Node set Functions name(): return the name of the current node or the first node in the specified node set. local-name(): return the name of the current node or the first node in the specified node set without the namespace prefix. namespace-uri(): return the namespace URI of the current node or the first node in the specified node set. root(): return the root of tree text(): return the text of the current node Create by ChungLD faculty /36
  • 33. Boolean Functions This functions can be used with comparison operators in filter patterns and return true or false. boolean(arg): returns a boolean value for a number, string, or node set. not(arg): reversed value of arg true(): return true false(): return false Create by ChungLD faculty /36
  • 34. Numeric functions number(arg): return the numeric value of the arg ( arg could be a boolean, a string or a node set) ceiling(number) floor(number) round(number) Create by ChungLD faculty /36
  • 35. String Functions string(arg) translate(string, string ,string) concat(string,string,…) substring(string, start, len) Create by ChungLD faculty /36
  • 36. Transforming XML using XSLT The transformation of XML document can be done in various steps: Step 1 Start by creating a normal XML document <?xml version=“1.0” encoding=“utf-8”?> Step 2 Then add the lines shown below to create an XSL Stylesheet: <xsl:stylesheet xmlnx:xsl= http://www.w3.org/1999/xsl/transform version=“1.0”> … .. </xsl:stylesheet> Step 3 Now, set it up to produce HTML – compatible ouput <xsl:stylesheet> <xsl:output method=“html”/> … . </xsl:stylesheet> Create by ChungLD faculty /36 XPath Tree
  • 37. Summary and workshop Create by ChungLD faculty /36