Download presentation
Presentation is loading. Please wait.
Published byDuane McKenzie Modified over 9 years ago
1
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy
2
XML Stylesheet Langugae Extensible Stylesheet Language (XSL) Language for document transformation Transformation Converting XML to another form Formatting objects Layout of XML document Search document contents Navigating XML document tree nodes http://www.codeproject.com/Articles/294380/Applying-XSLT-Stylesheet-to-an-XML-File-at-Runtime
3
XML Stylesheet Language XSL-FO XSLT XPath Navigating XML Document Formatting XML Document Transforming XML Document
4
CSS (Cascading Style Sheets) CSS = Style Sheets for HTML HTML uses predefined tags, and the meaning of each tag is well understood. The tag in HTML defines a table - and a browser knows how to display it. Adding styles to HTML elements are simple. Telling a browser to display an element in a special font or color, is easy with CSS.
5
XML Style Sheets XSL = Style Sheets for XML XML does not use predefined tags (we can use any tag-names we like), and therefore the meaning of each tag is not well understood. A tag could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it. XSL describes how the XML document should be displayed!
6
XSL In Parts XSL - More Than a Style Sheet Language XSL consists of three parts: – XSLT - a language for transforming XML documents – XPath - a language for navigating in XML documents – XSL-FO - a language for formatting XML documents
7
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
8
XSLT = XSL Transformations XSLT is the most important part of XSL. XSLT is used to transform an XML document into another XML document – Or another type of document that is recognized by a browser, like HTML and XHTML. – Normally XSLT does this by transforming each XML element into an (X)HTML element.
9
XSLT = XSL Transformations With XSLT you can add/remove elements and attributes to or from the output file. – You can also rearrange and sort elements, – Perform tests and make decisions about which elements to hide and display, and a lot more. A common way to describe the transformation process is to say that XSLT transforms an XML source-tree into an XML result-tree.
10
Browsers Support for XSLT Mozilla Firefox – Firefox supports XML, XSLT, and XPath from version 3. Internet Explorer – Internet Explorer supports XML, XSLT, and XPath from version 6. – Internet Explorer 5 is NOT compatible with the official W3C XSL Recommendation. Google Chrome – Chrome supports XML, XSLT, and XPath from version 1. Opera – Opera supports XML, XSLT, and XPath from version 9. Opera 8 supports only XML + CSS. Apple Safari – Safari supports XML and XSLT from version 3.
11
Example Study How to transform XML into XHTML using XSLT.
12
Transform XML into XHTML 1.Style Sheet Declaration 2.Start with a Raw XML Document 3.Create an XSL Style Sheet 4.Link the XSL Style Sheet to the XML Document
13
Style Sheet Declaration W3C XSLT Recommendation The official W3C XSLT namespaceMust attribute, value pair top
14
Raw XML Document Empire Burlesque Bob Dylan USA Columbia 10.90 1985..
15
An XSL Style Sheet My CD Collection Title Artist XML document declaration This document is a Stylesheet
16
Linking XML with Stylesheet Empire Burlesque Bob Dylan USA Columbia 10.90 1985..
17
XSL Templates 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.
18
XSL Templates The Element – Used to build templates The match attribute – Associates a template with an XML element. – Also 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).
19
XSL Templates The element defines a template. The match="/" attribute associates the template with the root of the XML source document. The content inside the element defines some HTML to write to the output.
20
Xpath Expressions Path ExpressionResult bookstore /bookstore bookstore/book //book bookstore//book //@lang Harry Potter 29.99 XML 4 Dummies 39.95 The Han River 149.95
21
Example XSL Style Sheet My CD Collection Title Artist.. XML document declaration This document is a Stylesheet End of template End of stylesheet associates the template with the root of the XML source document HTML to write to the output
22
Output
23
Stylesheet Nuts&Bolts The Element – Extract the value of an XML element and add it to the output stream of the transformation – The select attribute contains an XPath expression
24
Example XSL Style Sheet My CD Collection Title Artist XML document declaration This document is a Stylesheet End of template End of stylesheet Selecting a specific element value HTML to write to the output
25
Output
26
Stylesheet Nuts&Bolts The Element – select every XML element of a specified element list – Note: An XPath expression in value of select.
27
Example XSL Style Sheet My CD Collection Title Artist XML document declaration This document is a Stylesheet End of template End of stylesheet Selecting each element in a list of elements HTML to write to the output
28
Output
29
Filtering the Output using Predicates Path ExpressionResult /bookstore/book[1] /bookstore/book[last()] /bookstore/book[last()-1] /bookstore/book[position()<3] //title[@lang] //title[@lang=‘kor'] /bookstore/book[price>35.00] /bookstore/book[price>35.00]/title Harry Potter 29.99 XML 4 Dummies 39.95 The Han River 149.95
30
Example XSL Style Sheet My CD Collection Title Artist XML document declaration This document is a Stylesheet End of template End of stylesheet Filtering output HTML to write to the output
31
Output ?
32
Stylesheet Nuts&Bolts The Element – Sort the out put wrt select value – Value of select is ?.
33
Example XSL Style Sheet My CD Collection Title Artist XML document declaration This document is a Stylesheet End of template End of stylesheet Sorting output HTML to write to the output
34
Output
35
Stylesheet Nuts&Bolts Placement: The element always inside the element Attribute: The Value of test is an XPath expression.
36
Example XSL Style Sheet My CD Collection Title Artist Price 10”> predicate HTML to write to the output
37
Output
38
Stylesheet Nuts&Bolts The,, and – a multiple conditional test against the XML file, add... some output...... some output....
39
Stylesheet Nuts&Bolts
40
Output
41
My CD Collection Title: Artist:
42
Output
43
References W3 Schools – http://www.w3schools.com/ http://www.w3schools.com/ Online XSLT Test Tool – http://xslttest.appspot.com/ http://xslttest.appspot.com/
44
Thanks
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.