1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.

Slides:



Advertisements
Similar presentations
XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
Advertisements

1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
XSLT (eXtensible Stylesheet Language Transformation) 1.
+ XSL eXtensible Stylesheet Language. + 2 XML Lecture Adapted from the work of Prof Mark Baker ACET, University of Reading.
XML and XSL Transforming your XML documents with eXtensible Stylesheet Language Transformations [Optional Lecture]
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)
1 XSL – XML Stylesheet Language. 2 XSL XSL = XML Stylesheet Language XSL cosists of –XPath (navigation in documents) –XSLT (T for transformations) –XSLFO.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
Rendering XML documents with XSL The most powerful approaches to rendering XML documents involve using XSL (eXtensible Stylesheet Language) XSL enables.
XSL Transformations (XSLT) Meghasyam Bokam April’1 st, 2002.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
XSL Unit 6 November 2. XSL –eXtensible Stylesheet Language –Basically a stylesheet for XML documents XSL has three parts: –XSLT –XPath –XSL-FO.
1 Copyright (c) [2000]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents Roger L. Costello XML Technologies.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
CS 4408 Lecture 9. XSLT instruction elements We have seen that a template can contain non-XSLT text, canned text that it inserts into the result tree.
1 XPATH Modified Slides from Dr. Sagiv. 2 XPath A Language for Locating Nodes in XML Documents XPath expressions are written in a syntax that resembles.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
Object Oriented Programming III1 XSLT Processing XML using XSLT Using XPath.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
SD2520 Databases using XML and JQuery
Using XSLT and XPath to Enhance HTML Documents Reference: Roger L. Costello
XSLT XSLT: eXtensible Stylesheet Language for Transformations - a language for transforming XML documents into any text- based format (e.g. HTML, plain.
ECA 228 Internet/Intranet Design I Intro to XSL. ECA 228 Internet/Intranet Design I XSL basics W3C standards for stylesheets – CSS – XSL: Extensible Markup.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.
1 cs XSL XSL is a standard that consists of three parts: XPath (navigation in documents) XPath was taught in the DB course, so it will not be.
XSL XML Stylesheet Langauage. XPath Notation for addressing elements in an XML document /xyz - selects the root element /xyz/abc - selects all elements.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
1 XML Data Management 7. XLST Werner Nutt. Kernow and Saxon To demo XSLT, we use Kernow –Kernow is a (graphical) front end for Saxon Saxon is an XSLT,
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
CIS 375—Web App Dev II XSL. 2 XSL Introduction XSL stands for _____________________________. XSL is the language used for manipulating and displaying.
Lecture 11 XSL Transformations (part 1: Introduction)
XPath Aug ’10 – Dec ‘10. XPath   XML Path Language   Technology that allows to select a part or parts of an XML document to process   XPath was.
 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 – XSL: Extensible Stylesheet Language Transformations (XSLT) Outline 12.1Introduction 12.2Setup.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Applying eXtensible Style Sheets (XSL) Ellen Pearlman Eileen Mullin Programming.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
1 cs XSL XSL is a standard that consists of three parts: XPath (navigation in documents) XPath was taught in the DB course, so it will not be.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
1 XML Data Management Extracting Data from XML: XPath Werner Nutt based on slides by Sara Cohen, Jerusalem.
1 Copyright (c) [2000]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents Roger L. Costello XML Technologies.
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
XPath. XPath, the XML Path Language, is a query language for selecting nodes from an XML document. The XPath language is based on a tree representation.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
1 XML Data Management XLST Werner Nutt. A Hello World! Stylesheet world.
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
1 XMLXSL(T) and CSS NOEA/PQC (rev. fen) 2007 Stylesheets CSS:Cascading Style Sheets XSL(T):eXtended Stylesheet Language (Transformations)
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
1 XPath Extracting Data from XML. 2 Data stored in an XML document must be extracted to use with various applications Data can be extracted programmatically.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
XML Schema – XSLT Week 8 Web site:
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
CH 15 XSL Transformations 1. Objective What is XSL? Overview of XSL transformations Understanding XSL templates Computing the value of a node with xsl:value-of.
Session IV Chapter 14 – Chapter 14 – XSLThttp://
CS 431 – February 28, 2005 Carl Lagoze – Cornell University
Modified Slides from Dr. Sagiv
Modified Slides from Dr. Sagiv
Presentation transcript:

1 XSL Transformations (XSLT)

2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath to navigate in XML documents. An XSLT program is itself an XML document (called an XSL stylesheet) that describes the transformation process for input (XML) documents.

3 XSLT is rule-based XSLT is different from conventional programming languages because XSLT is based on template rules which specify how XML documents should be processed. The stylesheet declares what output should be produced when a pattern in the XML document is matched.

4 Dark Side of the Moon Pink Floyd Space Oddity David Bowie 9.90 Aretha: Lady Soul Aretha Franklin 9.90 catalog.xml

5 Style Sheet Declaration The root element that declares the document to be an XSL style sheet is or. Note: and are completely synonymous and either can be used! The correct way to declare an XSL style sheet according to the W3C XSLT Recommendation is: or:

6 <xsl:stylesheet version="1.0" xmlns:xsl=" cd catalog This is a cd catalog! Valid XML! Commands are XML elements with the namespace xsl catalog.xsl Includes XHTML elements

7 How Does XSLT Work? An XSL stylesheet is a collection of templates that are applied to source nodes (i.e., nodes of the given XML) Each template has a match attribute that specifies to which source nodes the template can be applied Each source node has a template that matches it The current source node is processed by applying a template that matches this node When processing a node, it is possible (but not necessary) to recursively process other nodes, e.g., the children of the processed node The XSLT processor processes the document root ( / )

8 Templates A template has the form... The content of a template consists of -XML elements (e.g., XHTML) and text that are copied to the result -XSL elements ( ) that are actually instructions The pattern syntax is a subset of XPath

9 <xsl:stylesheet version="1.0" xmlns:xsl=" cd catalog This is a cd catalog! catalog1.xsl

10 Dark Side of the Moon Pink Floyd Space Oddity David Bowie 9.90 Aretha: Lady Soul Aretha Franklin 9.90 catalog1.xml

11

12 match 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). If the path starts with a slash ( / ) it always represents an absolute path to an element!

13 Examples of Match Attributes match="cd", -All elements with tag name cd match="//cd", match="/catalog/cd/artist" -All matches of the absolute XPath match="cd/artist" -All artist nodes that have a cd parent match="catalog//artist" -All artist nodes that have a catalog ancestor

14 My CD Collection Title Artist..

15 Frequently Used Elements of XSL -This element extracts the value of a node from the node list located by xpath -This element loops over all the nodes in the node list located by xpath The element is used to sort the list of nodes that are looped over by the element -Thus, the must appear inside the element -The looping is done in sorted order

16 My CD Collection Title Artist

17 My CD Collection Title Artist

18 My CD Collection Title Artist

19 My CD Collection Title Artist

20,, etc. -This element is for conditional processing The element is used in conjunction with and to express multiple conditional tests. Frequently Used Elements of XSL (cont)

21 My CD Collection Title Artist

22

23 Tells the processor to continue processing other nodes in the input document and instantiate their matching templates. Processing starts by applying a template to the root. -If no specified template matches the root, then one is inserted by default (see slide 25) <xsl:apply-templates>

24 (cont) (cont) The XSL stylesheet must specify explicitly whether templates should be applied to descendants of a node. This is done by putting inside a template the instruction: In xpath, the current processed node is used as the context node Without the select attribute, this instruction processes all the children of the current node (including text nodes).

25 Default Templates XSL provides implicit built-in templates that match every element and text nodes. Templates we write always override these built-in templates (when they match). selects from the root node and matches any element node matches text & attributes nodes

26 <xsl:stylesheet version="1.0" xmlns:xsl=" Dark Side of the Moon Pink Floyd Space Oddity David Bowie 9.90 … No template! default template is used

27 <xsl:stylesheet version="1.0" xmlns:xsl=" A cd! A cd! The template applies to all of the CDs.

28 <xsl:stylesheet version="1.0" xmlns:xsl=" A cd! A cd! Aretha: Lady Soul Aretha Franklin 9.90 The template doesn’t apply to Aretha Franklin’s CD, default template used here.

29 <xsl:stylesheet version="1.0" xmlns:xsl=" <xsl:apply-templates An artist! An artist! Matches the root – default template will not be applied instead of outputting a fixed response, it instantiates the template for each matching artist element

30 <xsl:stylesheet version="1.0" xmlns:xsl=" <xsl:apply-templates An artist! No match! “catalog” is missing Matches the root – default template will not be applied

31 Setting Values in Attributes We can insert expressions into attribute values, by putting the expression inside curly braces ( {} ). Alternatively, we can use in order to construct XML elements.

32 An Example In the following example, we add to each CD entitled ”title” a link to the URL /showcd.html?title= ”title” :

33

34 Using Using : showcd/?title=

35 On XSL Code Typically, an XSLT program can be written in several, very different ways -Templates can sometime replace loops and vice versa -Conditions can sometimes be replaced with XPath predicates (e.g., in the select attribute) and vice versa A matter of convenience and elegancy

36 Identity Transformation Stylesheet Suppose that we want to write an XSL stylesheet that generates a copy of the source document -It is rather easy to do it when the structure of the source XML document is known Can we write an XSL stylesheet that does it for every possible XML document? -Yes! (see next slide)

37 <xsl:stylesheet xmlns:xsl=" version="1.0"> Identity Transformation Stylesheet defines the format of the output document any element node any attribute node

38 Generating Valid XHTML By default, the documents that XSL stylesheets generate are not valid XHTML Next, we will show how XSL stylesheet can be changed in order to generate valid XHTML

39 <xsl:stylesheet version="1.0" xmlns:xsl=" cd catalog This is a cd catalog! The Original XSL Example

40 <xsl:stylesheet version="1.0" xmlns:xsl=" xmlns=" <xsl:output method="html" doctype-public= "-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system= " "/> … Modifying the XSL Example

41 cd catalog This is a cd catalog! The Transformation Result

42 Some Other XSL Elements The element inserts free text in the output The creates a copy of the specified nodes, to insert a result tree fragment into the result tree The element creates a comment node in the result tree The element defines a variable (local or global) that can be used within the program

43 The End! These slides are based on: Slides developed for the course: Tutorial: