Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.

Similar presentations


Presentation on theme: "1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects."— Presentation transcript:

1 1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects

2 2 XML Revision Say Bye Bye, Sweep Bye Bye, Sweep

3 3 Well formed XML  Begins with XML declaration  Has one unique root element  Non-empty elements have closing tags  Empty elements terminated  Tags appear in correct order  Attribute values quoted

4 4 Valid XML  Valid documents are well formed  Conform to a DTD –Correct sequence –Correct nesting –Valid attribute values

5 5 Document Type Definition <!DOCTYPE sweepjoke [ ]>

6 6 Validating Parser

7 7 Not Well Formed Say Bye Bye, Sweep Bye Bye, Sweep

8 8 Invalid 1 Hello Say Bye Bye, Sweep Bye Bye, Sweep

9 9 Invalid 2 Bye Bye, Sweep

10 10 Invalid 3 Say Bye Bye, Sweep Bye Bye, Sweep Hello Sooty

11 11 Is This Valid? 1 Hello Sooty Say Bye Bye, Sweep Bye Bye, Sweep

12 12 Is This Valid? 2 Say Bye Bye, Sweep Bye Bye, Sweep Hello Sooty

13 13 Namespaces in XML  An XML namespace is a collection of names –Identified by a URI reference [RFC2396] –Used in XML documents as element types and attribute names

14 14 Namespace Definition <!--the "edi" prefix is bound to http://ecommerce.org/schema for the "x" element and contents -->

15 15 Namespace use <!-- the 'price' element's namespace is http://ecommerce.org/schema --> 32.18

16 16 Structured Publishing Taken from an example given by Jon Bosak

17 17 XSL  eXtensible Stylesheet Language  Three parts –XSLT Language for transforming XML documents –XPath Language for defining parts of an XML document –XSL Formatting Objects Vocabulary for formatting XML documents

18 18 XSLT  XSL Transformations  Transforms from an XML source tree to an XML result tree  Typically used to transform XML to XHTML

19 19 Transformation Process  Use XPath to define parts of the document that match predefined templates  On match, transform source into result  Unmatched parts of the source copied unmodified to result

20 20 Browser Support  IE 5.0 and 5.5 not 100% compatible  IE 6.0 supports all W3C recommendations  Fully supported in Netscape 7.x  Fully supported in Mozilla 1.3

21 21 Demo XML File Web Information Systems Easy! Prog in Java Hard

22 22 Required Output

23 23 Untransformed View

24 24 HTML Output ModuleList Module Number Name Information

25 25 HTML Output CP3024 Web Information Systems Easy! CP2027 Prog in Java Hard

26 26 Style Sheet Declaration  XSL stylesheets are written as XML  First line identifies file as XML  Second line should be: – or –

27 27 XSL Template  The element contains rules to apply when a specified node is matched  The match attribute is used to associate the template with an XML element  E.g.  Use of / selects root (whole document)  Closes with

28 28 Example Stylesheet <xsl:stylesheet version = "1.0" xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> Module List

29 29 Example Stylesheet Module Number Name Information

30 30 Output

31 31 Applying A Stylesheet Web Information Systems Easy! Prog in Java Hard

32 32 XML Tree Representation

33 33 XPath  Identifies parts of an XML document  Can select a node –module  Select direct descendant –moduleList/module  Select any descendant –moduleList//comment  Select attribute –@no

34 34 XSL For-Each  Used to select every node of a specified set  E.g  The select attribute contains an Xpath expression  It defines the context for the enclosed expressions

35 35 XSL Value-Of  Selects the value of an XML element  Adds it to the output  E.g.  The select attribute contains an Xpath expression  This determines what is added to the output

36 36 Outputting Elements

37 37 Output

38 38 Applying A Filter  Can use for-each statement to select entries  E.g.

39 39 Sorting Output  Can use xsl:sort

40 40 XSL:Sort  Select attribute indicates which attribute to sort on

41 41 XSL Formatting Objects Source: W3C

42 42 XSLT Transform Source: W3C

43 43 Formatting Source: W3C

44 44 Final Formatting Source: W3C

45 45 Summary  XML revisited –Well formed –Valid  XSL –XSLT –XPath –XSL Formatting Objects


Download ppt "1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects."

Similar presentations


Ads by Google