Presentation is loading. Please wait.

Presentation is loading. Please wait.

XSLT XSLT: eXtensible Stylesheet Language for Transformations - a language for transforming XML documents into any text- based format (e.g. HTML, plain.

Similar presentations


Presentation on theme: "XSLT XSLT: eXtensible Stylesheet Language for Transformations - a language for transforming XML documents into any text- based format (e.g. HTML, plain."— Presentation transcript:

1 XSLT XSLT: eXtensible Stylesheet Language for Transformations - a language for transforming XML documents into any text- based format (e.g. HTML, plain text, another XML, etc.) - Why do we need to learn it? - A typical work flow: legacy data source > XML > XSL transformation > application/Web browser XPath - a language for navigating in XML documents (XSLT uses XPath to find information in an XML document. XPath is used to navigate through elements and attributes in XML documents) XSL-FO - a language for formatting XML documents

2 How Does It Work: XSLT stylesheet XML document XSLT processor Transformed XML/HTML document An XSLT processor can be built into a web browser, or can be a standalone program run from the command (e.g. SAXON or Apache Xalan)

3 Example source XML file: http://www.w3schools.com/xsl/cdcatalog.xml XSLT stylesheet: http://www.w3schools.com/xsl/cdcatalog.xsl Link the XSL Style Sheet to the XML Document: http://www.w3schools.com/xsl/cdcatalog_with_xsl.xml Result XML file: http://www.w3schools.com/xsl/cdcatalog_with_ex1.xml

4 Example source xml file: http://www.w3schools.com/xsl/cdcatalog.xml XSLT stylesheet: http://www.w3schools.com/xsl/cdcatalog.xsl Link the XSL Style Sheet to the XML Document: http://www.w3schools.com/xsl/cdcatalog_with_xsl.xml Result XML file: http://www.w3schools.com/xsl/cdcatalog_with_ex1.xml Empire Burlesque Bob Dylan USA Columbia 10.90 1985...

5 Example source xml file: http://www.w3schools.com/xsl/cdcatalog.xml XSLT stylesheet: http://www.w3schools.com/xsl/cdcatalog.xsl Link the XSL Style Sheet to the XML Document: http://www.w3schools.com/xsl/cdcatalog_with_xsl.xml Result XML file: http://www.w3schools.com/xsl/cdcatalog_with_ex1.xml My CD Collection Title Artist

6 Example source xml file: http://www.w3schools.com/xsl/cdcatalog.xml XSLT stylesheet: http://www.w3schools.com/xsl/cdcatalog.xsl Link the XSL Style Sheet to the XML Document: http://www.w3schools.com/xsl/cdcatalog_with_xsl.xml Result XML file: http://www.w3schools.com/xsl/cdcatalog_with_ex1.xml Empire Burlesque Bob Dylan USA Columbia 10.90 1985...

7 Example source XML file: http://www.w3schools.com/xsl/cdcatalog.xml XSLT stylesheet: http://www.w3schools.com/xsl/cdcatalog.xsl Link the XSL Style Sheet to the XML Document: http://www.w3schools.com/xsl/cdcatalog_with_xsl.xml Result XML file: http://www.w3schools.com/xsl/cdcatalog_with_ex1.xml My CD Collection Title Artist Empire Burlesque Bob Dylan …

8 Template Rules templatesAn XSL style sheet consists of one or more set of rules that are called templates. template elementsEach template rule tells the XSLT processor how to handle the specific elements in the input XML document.

9 Template Rules (Example) root element sub-element “cd” of “catalog” … title: value of element “title”

10 Structure of a stylesheet …… \ template > a template rule / ……

11 Processing Model For a given input XML document, the output is obtained as follows: - The source tree is processed by processing the root node - a node list is processed by processing each node in order and concatenating the results - a single node is processed by: finding the template rule with the matching pattern, and creating result fragment

12 My CD Collection Title Artist Empire Burlesque Bob Dylan USA Columbia 10.90 1985 … My CD Collection TitleArtist Empire BurlesqueBob Dylan

13 XSL:for-each <xsl:for-each select = “node-set-expression” XSL:if <xsl:if test = “boolean-expression” XSL:sort <xsl:sort select = “string-expression” data-type = “text” | “number” | “prefixedName” lang = “langcode” order = “ascending” | “descending” case-order = “upper-first” | “lower-first” />

14 My CD Collection Title Artist My CD Collection TitleArtist Empire BurlesqueBob Dylan Greatest HitsDolly Parton The very best ofCat Stevens

15 My CD Collection Title Artist My CD Collection TitleArtist Empire BurlesqueBob Dylan filter

16 My CD Collection Title Artist My CD Collection TitleArtist Empire BurlesqueBob Dylan The very best ofCat Stevens Greatest HitsDolly Parton Sort On an element

17 My CD Collection Title Artist My CD Collection TitleArtist Empire BurlesqueBob Dylan Greatest HitsDolly Parton if test inside

18 My CD Collection Title Artist My CD Collection TitleArtist Empire BurlesqueBob Dylan The very best ofCat Stevens Greatest HitsDolly Parton Multiple conditional test

19 My CD Collection Title Artist … My CD Collection TitleArtist Empire BurlesqueBob Dylan The very best ofCat Stevens Greatest HitsDolly Parton Multiple conditional test 2

20 XSL:apply-templates <xsl:apply-templates select=“node-set-expression” mode=“qualifiedName”> Without xsl:sort child elements, the default is in document order; xsl:with-param child elements can be used to pass parameter values to the matched templates

21 My CD Collection Title: Artist: My CD Collection Title: Empire Burlesque Artist: Bob Dylan Title: Hide your heart Artist: Bonnie Tyler Title: Greatest Hits Artist: Dolly Parton

22 … Born: Died: … Select attribute value in … Born: 1918 Died: 1988 …

23 <name first=“{first_name}” initial=“{middle_initial}” last=“{last_name}” /> /xsl:template> … Attribute Value Templates Richard P Feynman

24 Using oXygen XML Editor

25 Other Issues in Practice XPath - a language for finding information in an XML document. http://www.w3schools.com/xpath/default.asp XPath functions Be aware of the “context” Namespace (e.g. “dc:author”) http://www.ibm.com/developerworks/xml/library/x-nmspace.html http://www.ibm.com/developerworks/xml/library/x-nmspace2.html

26 References: This PPT is based on XSLT Tutorial at: http://www.w3schools.com/xsl/ http://www.w3schools.com/xsl/ Zvon XSL Tutorial: http://www.zvon.org/xxl/XSLTutorial/Output/index.html http://www.zvon.org/xxl/XSLTutorial/Output/index.html XSLT reference: http://www.zvon.org/xxl/XSLTreference/Output/index.html http://www.w3schools.com/xsl/xsl_w3celementref.asp


Download ppt "XSLT XSLT: eXtensible Stylesheet Language for Transformations - a language for transforming XML documents into any text- based format (e.g. HTML, plain."

Similar presentations


Ads by Google