Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.

Similar presentations


Presentation on theme: "Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT."— Presentation transcript:

1 Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT

2 Sheet 2XML Technology in E-Commerce 2001Lecture 6 XPointer –Purpose: specifying fragment identifiers for XML documents; –Points and Ranges; –Extensions to XPath; –XPointer Forms; XSLT –Rendering XML; –XSL Suite; –Example; –XSLT Elements; Lecture Outline

3 Sheet 3XML Technology in E-Commerce 2001Lecture 6 XML XML Namespaces XPath XPointerXSLT XLink XML Schema XML Languages Parser DOMSAX Software Application Overview

4 Sheet 4XML Technology in E-Commerce 2001Lecture 6 Fragment Identifiers The part after “#” character in URIs is called fragment identifier: http://some.site.net/path/myFile.html#introduction; http://some.site.net/path/myXML.xml#id001’ Fragment identifier specifies retrieval action on the resource; The syntax and interpretation of fragment identifiers are media dependent;

5 Sheet 5XML Technology in E-Commerce 2001Lecture 6 XPointer Specifies language for expressing fragment identifiers for XML documents; Addresses internal structures of XML documents; Extends XPath; Provides facilities for: –selection of a specific position in an XML document; –selection of a range in an XML document; Current status: Working Draft; http://www.w3.org/TR/xptr

6 Sheet 6XML Technology in E-Commerce 2001Lecture 6 Points and Ranges img competition resultsphotos img name John SmithD. WarwickM. Douglas Point 1 Container: Text Index: 5 Range Point 2 Container: Text Index: 2 Range Point 1 Container: photos Index: 0 Point 2 Container: photos Index: 2 DOM representation of a sample XML document:

7 Sheet 7XML Technology in E-Commerce 2001Lecture 6 XPointer Terms Point - position in XML information. Consists of container node and index; Range - all the information between two end points; Location - XPath’s nodes plus points and ranges; Location set - ordered list of locations. Usually a result of XPointer expression; Location and Location set are a generalization of XPath’s Node and Node set

8 Sheet 8XML Technology in E-Commerce 2001Lecture 6 Extensions to XPath XPath allows locating subset of nodes; XPointer allows locating parts that are not nodes. Points and Ranges extend the notion of Node; XPointer expression yields object of type location set; Evaluation is made relatively to the root node of an XML document. The test for points and ranges uses point and range keywords;

9 Sheet 9XML Technology in E-Commerce 2001Lecture 6 XPointer Forms Full XPointers: xpointer(//contact[@id=“author02”]) xlink:href=“/contacts.xml#xpointer(//contact[@id=‘author 02’])” Bare names: short syntax for id() function: xpointer(id(“author02”)) xlink:href=“/contacts.xml#author02”

10 Sheet 10XML Technology in E-Commerce 2001Lecture 6 XPointer Functions range-to(expr). The start point is the context location. The end point is returned by the evaluation of expr; xpointer(id("chap1")/range-to(id("chap2"))) string-range(location-set, string). For each location in location-set, the function returns string ranges that match the string argument; string-range(//title,”Introduction")[4]

11 Sheet 11XML Technology in E-Commerce 2001Lecture 6 Summary on XPointer Specifies fragment identifiers in URIs; Still unstable, working draft status; Based on XPath; Implementations: –Fujitsu XLink Processor ; –libxml; –4XPointer;

12 Sheet 12XML Technology in E-Commerce 2001Lecture 6 XPointer –Purpose; –Points and Ranges; –Extensions to XPath; –XPointer Forms; XSLT –Rendering XML; –XSL Suite; –Example; –XSLT Elements; Lecture Outline

13 Sheet 13XML Technology in E-Commerce 2001Lecture 6 Rendering XML HTML specifies how the documents are rendered; In general, XML-based languages do not specify how the documents are rendered; Problem: How to render XML documents on different devices? XML Document

14 Sheet 14XML Technology in E-Commerce 2001Lecture 6 Rendering XML Solutions: –Attach CSS stylesheet; –Transformation in another document language understood by a particular device; XML Document CSS Stylesheet Browser Transformation FO Document HTML WML ? PDF

15 Sheet 15XML Technology in E-Commerce 2001Lecture 6 XSL XSL - Extensible Stylesheet Language. Language for expressing stylesheets; Two parts: –XSLT (Extensible Stylesheet Language for Transformations): Language for specifying transformations of XML documents. W3C Recommendation; –XSL Formatting Objects (XSL FO): XML vocabulary for expressing formatting semantics. W3C Candidate Recommendation; XSL W3C site: http://www.w3.org/Style/XSL/

16 Sheet 16XML Technology in E-Commerce 2001Lecture 6 Example What we have: Deitel XML Primer Paul Deitel Welcome Easy XML XML Elements? Entities

17 Sheet 17XML Technology in E-Commerce 2001Lecture 6 What we want: Example ISBN - 999-99999-9-x - Deitel XML Primer Deitel XML Primer Deitel, Paul Preface 1 Welcome (2 pages ) Chapter 1 Easy XML (4 pages ) Chapter 2 XML Elements? (2 pages ) Appendix 1 Entities (9 pages )

18 Sheet 18XML Technology in E-Commerce 2001Lecture 6 XSLT Basic Terms Transformation expressed in XSLT is called stylesheet; Stylesheet transforms a source tree into a result tree; Stylesheet is a set of template rules; Rules have two parts: –Pattern: selects nodes from the source tree. Uses XPath syntax; –Template: instantiated in order to form a part of the source tree; Source and result tree roughly conform to the XPath data model;

19 Sheet 19XML Technology in E-Commerce 2001Lecture 6 XSLT General Processing Scheme Stylesheet expressed in XSLT XSLT Processor Source tree Result tree

20 Sheet 20XML Technology in E-Commerce 2001Lecture 6 Source tree Result tree Instantiates Stylesheet XSLT Rule matching and Template Instantiation Rule 1 Rule 2 Rule 3 Matches

21 Sheet 21XML Technology in E-Commerce 2001Lecture 6 Demo Demo - modified version of Deitel 12.5, fig. 12.8 and 12.9, page 327; Tools: –XML Spy 3.5; –XSLT Processor: MSXML 3 Or any downloadable extension for Spy, e.g. Infoteria iXSLT or SAXON; Demo files: –book.xml; –style.xsl;

22 Sheet 22XML Technology in E-Commerce 2001Lecture 6 Demo Explained Stylesheet root element: ………………………………………………………….. Stylesheet contains elements from XSLT namespace. They are recognized and executed by the XSLT processor; Stylesheet includes non-XSLT elements. They can reside in their own namespace;

23 Sheet 23XML Technology in E-Commerce 2001Lecture 6 Template Rules First, the root node of the source tree is mapped to html element, which is the root element of all HTML documents, i.e. the root node of the result tree: processes all children of the current node. In our case the current node is the root node;

24 Sheet 24XML Technology in E-Commerce 2001Lecture 6 Getting Text from Source Tree ISBN - -, ………………………………………………… Element value-of:

25 Sheet 25XML Technology in E-Commerce 2001Lecture 6 Repetition Creating the table and the first row: ………… Preface ( pages ) for-each element instantiates the template for each node selected by the pattern. The selected node becomes the current node for the template;

26 Sheet 26XML Technology in E-Commerce 2001Lecture 6 Creating Elements We can reformulate a part of the previous template by using element XSLT element: Preface ( pages ) The template contained in the element, becomes the content of the element with name td in the result tree;

27 Sheet 27XML Technology in E-Commerce 2001Lecture 6 Creating Attributes We can reformulate a part of the previous template by using attribute XSLT element: Preface ( pages ) right Preface ( pages )

28 Sheet 28XML Technology in E-Commerce 2001Lecture 6 Copying Nodes XSLT element copy copies the current node and includes it in the result tree; The attributes and children are not copied; The template of the copy element generates their content; Example - identity transformation:

29 Sheet 29XML Technology in E-Commerce 2001Lecture 6 Demo Using XSLT to test the XPath expressions Demo - uses the file from Deitel Ex11.3, fig. 11.15, page 316; Tools: –XML Spy 3.5; –XSLT Processor: MSXML 3 Or any downloadable extension for Spy, e.g. Infoteria iXSLT or SAXON; Demo files: –transactions.xml; –xpath.xsl;

30 Sheet 30XML Technology in E-Commerce 2001Lecture 6 Processing Model At each step we have a list of source nodes; At the first step the list contains the root node; Each node is processed by finding the template rules with pattern that matches the node; Only one rule is selected; The template rule is instantiated with the node as a current node; XSLT instructions in the template are executed. They add new source nodes for processing; The process stops when the list of source nodes is empty;

31 Sheet 31XML Technology in E-Commerce 2001Lecture 6 Summary on XSLT Powerful transformation language for XML documents based on XML syntax; Allows multiple representations of a single document; Available software implementations: –MSXML 3; –iXSLT for Infoteria; –Saxon; –Xalan-Java, Xalan-C++, part of Apache XML Project; –XT;

32 Sheet 32XML Technology in E-Commerce 2001Lecture 6 Summary on XSLT (2) Read: Deitel 12; Assignment: Deitel Ex 12.3, Ex 12.7, page 351. For some hints see the course web site.


Download ppt "Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT."

Similar presentations


Ads by Google