Presentation is loading. Please wait.

Presentation is loading. Please wait.

September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.

Similar presentations


Presentation on theme: "September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof."— Presentation transcript:

1 September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof

2 September 15, 2003Houssam Haitof2 XSL XSL (eXtensible Stylesheet Language) is a language for expressing style sheets.

3 September 15, 2003Houssam Haitof3 What is a Stylesheet? A stylesheet is a file which contains a set of rules for converting an XML document into another document, which can be XML, HTML, plain text …

4 September 15, 2003Houssam Haitof4 Style Sheet Specifications XSL - Extensible Style Language Combines features of DSSSL and CSS using XML syntax DSSSL - Document Style and Semantics Specification Language An international SGML standard for Scheme-like languages for style sheets and document conversion CSS - Cascading Style Sheet Specification Simple syntax for assigning styles to elements (in some HTML browsers) XSLT is an XML Document!

5 September 15, 2003Houssam Haitof5 XSL It consists of three parts: XSL Transformations (XSLT): a language for transforming XML documents An XML vocabulary for specifying formatting semantics (XSL Formatting Objects) An expression language used by XSLT to access or refer to parts of an XML document (XPATH)

6 September 15, 2003Houssam Haitof6 XSL-FO Used to describe XML documents for display W3C recommendation 15 October 2001 A language for completely describing a styled document (content organization, styling, layouts and layout-selection rules) Everything needed to format and paginate a document!

7 September 15, 2003Houssam Haitof7 XPath Used in conjunction with XSLT Became a W3C recommendation 16 Nov 1999 Provides a language for pointing to different parts of an XML document specifies location path from specific context nodes (i.e. starting points)

8 September 15, 2003Houssam Haitof8 XPath Expressions Addresses a specific part or parts of XML documents which then allows XSLT to transform them Provides expressions for manipulation of strings, Booleans, numbers so that the XSL elements can act upon them

9 September 15, 2003Houssam Haitof9 XSLT XSLT is the most important part of the XSL Standard. It is the part of XSL that is used to transform an XML document into another XML document, or another type of document (text, java code, …)

10 September 15, 2003Houssam Haitof10 XSLT XSLT can be used to manipulate an XML document Can transform/extract information as a programming language can Can be used like a database language to extract information Uses XML syntax

11 September 15, 2003Houssam Haitof11 XSLT is rule-based XSLT is based on template rules which specify how XML documents should be processed. Template rules can be based in any order because XSLT is a declarative language. The stylesheet declares what output should be produced when a pattern in the XML document is matched.

12 September 15, 2003Houssam Haitof12 Example A stylesheet could declare that when the XSLT transformation engine finds a 'NAME' element it should add markup by calling the 'NAME' template. The template syntax is:...

13 September 15, 2003Houssam Haitof13 XSLT Capabilities Add prefix or suffix text to content Remove, create, re-order and sort elements Re-use elements elsewhere in the document Transform data between XML formats Uses a recursive mechanism to go through document

14 September 15, 2003Houssam Haitof14 XSLT consists of two parts A source document original xml document A result tree newly-created xml, html or a plain text document A common way to describe the transformation process is to say that XSL uses XSLT to transform an XML source tree into an XML result tree.

15 September 15, 2003Houssam Haitof15 Trees & Nodes With XSLT one does not think in terms of documents, but in terms of trees & nodes A tree represents the data in a document as a set of nodes Nodes are elements, attributes, comments, etc in a hierarchy

16 September 15, 2003Houssam Haitof16 Structure of Style Sheet style sheet Style sheet is made up of templates Templates have other XSL elements/XPath expressions Style sheet is usually given extension *.xsl Must be well-formed XML XSLT has a number of pre-defined elements to perform certain transformations …

17 September 15, 2003Houssam Haitof17 A Sample XML file Moby-Dick Herman Melville hardcover 724 $9.95 …

18 September 15, 2003Houssam Haitof18 A simple transformation of an XML file Book Description Author: Herman Melville Title: Moby-Dick Price: $9.95 Binding type: hardcover Number of pages: 724 Author: John Doe Title: Tales Price: $19.95 Binding type: softcover Number of pages: 450

19 September 15, 2003Houssam Haitof19 <xsl:stylesheet version ="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> XSLT Test Book Description Author: Title: Price: Binding: Number of Pages:

20 September 15, 2003Houssam Haitof20 XSL Processor An XSL processor can transform an input XML document to a XML or any other output document based on rules in a second XML document (i.e. a XSLT file)

21 September 15, 2003Houssam Haitof21 Template Matching XPath is used by XSLT in the match attribute of a template e.g. matches any sentence element. The stylesheet processor goes through the XML document one element at a time, finds the first template which that element matches, and carries out the instructions in that template.

22 September 15, 2003Houssam Haitof22 Template Matching (cont) If the element does not match any template in the stylesheet, then the default behaviour is for the processing to pass through to the children of this element without carrying out any instructions. When the processing reaches an element which has only text children, the result of processing these children is to print out the text.

23 September 15, 2003Houssam Haitof23 Some examples of patterns * matches any element / matches the top-level element sentence/word matches any word element with a sentence parent word[@pos=‘noun’] matches any noun element whose pos attribute has the value noun Many other possibilities …

24 September 15, 2003Houssam Haitof24 Some XSLT Syntax and Elements

25 September 15, 2003Houssam Haitof25 To begin Start by declaring that this is an xml document Next: declare the processing instruction & the namespace <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transfor m" version="1.0">

26 September 15, 2003Houssam Haitof26 XSLT Namespace Every XSL file needs to specify the XSL namespace so that the parser knows which version of XSLT to use. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transfor m" version="1.0"> The namespace prefix xsl: is used in the rest of the XSL file to identify XSL processing statements. If a statement isn't prefixed with xsl:, then it's simply copied to the output without being processed.

27 September 15, 2003Houssam Haitof27 XSL Elements Before processing can begin, the part of the XML document with the information to be copied to the output must be selected with an XPath expression. The selected section of the document is called a node and is normally selected with the match operator. If the entire document is to be selected, match the root node using match="/". Another approach is to match the document element (the element that includes the entire document).

28 September 15, 2003Houssam Haitof28 XSL Elements.. The element applies a template rule to the current element or to the current element's child nodes. If we add a select attribute to the element it will process only the child element that matches the value of the attribute.

29 September 15, 2003Houssam Haitof29 XSL Elements.. allows for processing on a number of nodes in the source tree, one at a time Attributes “select” denotes the path to the nodes Example.. // other xsl elements

30 September 15, 2003Houssam Haitof30 When the xsl:for-each expression has selected a ‘BOOKS' element, the xsl:value-of expression extracts and copies to the output file the value stored in the selected element. syntax: <xsl:value-of select= Examples XSL Elements..

31 September 15, 2003Houssam Haitof31 XSL Elements.. Allows for conditional processing. Attribute: test Example

32 September 15, 2003Houssam Haitof32 XSL Elements.. XSLT can be used to sort elements by alphabetical or numerical order, according to attribute values, text contents, in ascending or descending order, and more …

33 September 15, 2003Houssam Haitof33 More XSL Elements.. Some of the xsl elements not covered

34 September 15, 2003Houssam Haitof34 XSLT Thank you!


Download ppt "September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof."

Similar presentations


Ads by Google