Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Dr Alexiei Dingli XML Technologies X-Languages.

Similar presentations


Presentation on theme: "1 Dr Alexiei Dingli XML Technologies X-Languages."— Presentation transcript:

1 1 Dr Alexiei Dingli XML Technologies X-Languages

2 2 X Link X Pointer X Path X Query (Brief) X Form (Brief) XSLT FO Contents

3 3 X Languages X Query XPointer XLink X Path XSLT

4 4 Standard way of defining hyperlinks in XML Short for XML Linking Similar to HTML Links but more powerful Any element can have an XLink X Link

5 5 In HTML we use the tag In XML all tags can have a link <homepage xlink:type="simple" xlink:href="http://www.um.edu.mt"> University of Malta X Link Syntax

6 6 Declare the namespace in the top element Define a simple element i.e. Go from the current position to that address. Multidirectional are not supported by most browsers. xlink:type="simple" xlink:href="http://www.um.edu.mt" To define whether to use the current window or a new one... xlink:show="new" X Link Explanation

7 7 XLink gets more interesting when we want to access remote locations as resources, instead of standalone pages The value of the xlink:show attribute could have been set to "embed". This means that the resource should be processed inline within the page With XLink, you can also specify WHEN the resource should appear –xlink:actuate="onLoad" specifies that the resource should be loaded and shown when the document loads –xlink:actuate="onRequest" means that the resource is not read or shown before the link is clicked. This is very handy for low-bandwidth settings Advanced X Links

8 8 XML Pointer Language Allow hyperlinks to point to specific parts of an XML document Uses XPath for navigation X Pointer

9 9 If a hyperlink points to an XML document we can add an XPointer after the URL href="http://www.example.com/cdlist.xml#id('rock').child(5)" Find the element with unique Id rock Point to the 5 th item in the list X Pointer Example

10 10 href="http://www.example.com/cdlist.xml#id('rock') Is equivalent to href="http://www.example.com/cdlist.xml#rock X Pointer Short Hand

11 11 Lies at the heart of the XML technologies Is a syntax for defining parts of document Uses path expressions to navigate Contains a library of standard function (over 100) Major element of XSLT X Path

12 12 Element Attribute Text Namespace Processing-instruction ( ) Comment Root node X Path Nodes

13 13 Parent Children Siblings Ancestors Descendants Node relationships

14 14 Harry Potter 29.99 Learning XML 39.95 Example

15 15 ExpressionDescription nodenameSelects all child nodes of the named node /Selects from the root node //Selects nodes in the document from the current node that match the selection no matter where they are.Selects the current node..Selects the parent of the current node @Selects attributes Usage

16 16 Path ExpressionResult bookstoreSelects all the child nodes of the bookstore element /bookstoreSelects the root element bookstore Note: If the path starts with a slash ( / ) it always represents an absolute path to an element! bookstore/bookSelects all book elements that are children of bookstore //bookSelects all book elements no matter where they are in the document bookstore//bookSelects all book elements that are descendant of the bookstore element, no matter where they are under the bookstore element //@langSelects all attributes that are named lang Examples

17 17 Path ExpressionResult /bookstore/book[1]Selects the first book element that is the child of the bookstore element.Note: IE5 and later has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]!! /bookstore/book[last()]Selects the last book element that is the child of the bookstore element /bookstore/book[last()-1]Selects the last but one book element that is the child of the bookstore element /bookstore/book[position()<3]Selects the first two book elements that are children of the bookstore element //title[@lang]Selects all the title elements that have an attribute named lang //title[@lang='eng']Selects all the title elements that have an attribute named lang with a value of 'eng' /bookstore/book[price>35.00]Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00 /bookstore/book[price>35.00]/titleSelects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00 Example predicates

18 18 WildcardDescription *Matches any element node @*Matches any attribute node node()Matches any node of any kind Using Wildcards Path ExpressionResult /bookstore/*Selects all the child nodes of the bookstore element //*Selects all elements in the document //title[@*]Selects all title elements which have any attribute

19 19 Path ExpressionResult //book/title | //book/priceSelects all the title AND price elements of all book elements //title | //priceSelects all the title AND price elements in the document /bookstore/book/title | //priceSelects all the title elements of the book element of the bookstore element AND all the price elements in the document Selecting several paths

20 20 AxisNameResult ancestorSelects all ancestors (parent, grandparent, etc.) of the current node ancestor-or-selfSelects all ancestors (parent, grandparent, etc.) of the current node and the current node itself attributeSelects all attributes of the current node childSelects all children of the current node descendantSelects all descendants (children, grandchildren, etc.) of the current node descendant-or-selfSelects all descendants (children, grandchildren, etc.) of the current node and the current node itself followingSelects everything in the document after the closing tag of the current node following-siblingSelects all siblings after the current node namespaceSelects all namespace nodes of the current node parentSelects the parent of the current node precedingSelects everything in the document that is before the start tag of the current node preceding-siblingSelects all siblings before the current node selfSelects the current node Axes

21 21 an axis (defines the tree-relationship between the selected nodes and the current node) a node-test (identifies a node within an axis) zero or more predicates (to further refine the selected node-set) axisname::nodetest[predicate] Location step

22 22 ExampleResult child::bookSelects all book nodes that are children of the current node attribute::langSelects the lang attribute of the current node child::*Selects all children of the current node attribute::*Selects all attributes of the current node child::text()Selects all text child nodes of the current node child::node()Selects all child nodes of the current node descendant::bookSelects all book descendants of the current node ancestor::bookSelects all book ancestors of the current node ancestor-or-self::bookSelects all book ancestors of the current node - and the current as well if it is a book node child::*/child::priceSelects all price grandchildren of the current node Location step example

23 23 An absolute location path: /step/step/... A relative location path: step/step/... The difference is the initial / Absolute vrs Relative

24 24 OperatorDescriptionExampleReturn value |Computes two node-sets//book | //cdReturns a node-set with all book and cd elements +Addition6 + 410 -Subtraction6 - 42 *Multiplication6 * 424 divDivision8 div 42 =Equalprice=9.80true if price is 9.80 false if price is 9.90 !=Not equalprice!=9.80true if price is 9.90 false if price is 9.80 <Less thanprice<9.80true if price is 9.00 false if price is 9.80 <=Less than or equal toprice<=9.80true if price is 9.00 false if price is 9.90 >Greater thanprice>9.80true if price is 9.90 false if price is 9.80 >=Greater than or equal toprice>=9.80true if price is 9.90 false if price is 9.70 or price=9.80 or price=9.70true if price is 9.80 false if price is 9.50 and price>9.00 and price<9.90true if price is 9.80 false if price is 8.50 modModulus (division remainder)5 mod 21

25 25 xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("books.xml"); xpath="/bookstore/book[1]/title"; xmlDoc.selectNodes(xpath); Programming example

26 26 Designed to query XML Data Like SQL for databases Built on XPath X Query

27 27 doc("books.xml")/bookstore/book/title Load the document and use XPath to get the data For more powerful queries use FLWOR expressions XQuery Example

28 28 Similar to HTML forms but defined in XML Richer and more flexible Platform and device independent Standard in XHTML 2.0 X Forms

29 29 X Forms Example

30 30 The form The XML The Text X Forms Result

31 31 XML Stylesheet Language Consist of three parts –XSLT –Xpath –XSL-FO XSL

32 32 XSL Transformations Transforms XML to another XML document Uses XPath to navigate Most important part of XSL Supported by most browsers XSLT

33 33 Add Remove Sort Rearrange Perform Tests Make decisions Hide Etc... Power

34 34 Use XPath to define elements of source When a match occurs –Transform the matching part into the resulting document Workings

35 35 CD Catalogue (XML) CD Catalogue (XSL) CD Catalogue (XML + XSL) Combined by adding the following line in the XML document Example

36 36 Declaration part of a Stylesheet

37 37 XSL style sheet made up of different rules called templates The Match attribute is used to associate a template to an element in the XML document

38 38 Simple Template 1

39 39 Simple Template 1 Result

40 40 Simple Template 2

41 41 Simple Template 2 Result

42 42 Simple Template 3

43 43 Simple Template 3 Result

44 44 Simple Template 4

45 45 Simple Template 4 Result

46 46 Simple Template 5

47 47 Simple Template 5 Result

48 48 Simple Template 6

49 49 Simple Template 6 Result

50 50 Simple Template 7

51 51 Simple Template 7 Result

52 52 Simple Template 8

53 53 Simple Template 8 Result

54 54 Script to transform using Java Script and XSLTScript to transform using Java Script and XSLT From the Client Side

55 55 <% 'Load XML set xml = Server.CreateObject("Microsoft.XMLDOM") xml.async = false xml.load(Server.MapPath("cdcatalog.xml")) 'Load XSL set xsl = Server.CreateObject("Microsoft.XMLDOM") xsl.async = false xsl.load(Server.MapPath("cdcatalog.xsl")) 'Transform file Response.Write(xml.transformNode(xsl)) %> From the Server Side (ASP)

56 56 Language for formatting XML objects Can output to screen, paper and other media XML files with output information (layout and content) Normally stored in.fo,.fob or even.xml Formatting Objects

57 57 Example FO

58 58 < Root ^ Namespace < One or more page template < Page content Explanation

59 59 Pages (Contain many regions) Regions (Contain Block Areas) Block Areas (Contain Line Areas) Line Areas (Contain Inline Areas) Inline Areas Areas

60 60 region-body (the body of the page) region-before (the header of the page) region-after (the footer of the page) region-start (the left sidebar) region-end (the right sidebar) Regions

61 61 Page Regions

62 62 Page Example

63 63 Blocks flow into pages Flow

64 64 xsl-region-body (into the region-body) xsl-region-before (into the region-before) xsl-region-after (into the region-after) xsl-region-start (into the region-start) xsl-region-end (into the region-end) Where to flow?

65 65 Block Area

66 66 Block Example

67 67 Block Attributes (1) Block Margin –margin –margin-top –margin-bottom –margin-left –margin-right Border style attributes –border-style –border-before-style –border-after-style –border-start-style –border-end-style –border-top-style (same as border- before) –border-bottom-style (same as border- after) –border-left-style (same as border-start) –border-right-style (same as border-end) Border color attributes –border-color –border-before-color –border-after-color –border-start-color –border-end-color –border-top-color (same as border-before) –border-bottom-color (same as border-after) –border-left-color (same as border-start) –border-right-color (same as border-end) Border width attributes –border-width –border-before-width –border-after-width –border-start-width –border-end-width –border-top-width (same as border-before) –border-bottom-width (same as border-after) –border-left-width (same as border-start) –border-right-width (same as border-end)

68 68 Block Attributes (2) Block Padding –padding –padding-before –padding-after –padding-start –padding-end –padding-top (same as padding-before) –padding-bottom (same as padding-after) –padding-left (same as padding-start) –padding-right (same as padding-end) Block Background –background-color –background-image –background-repeat –background-attachment (scroll or fixed) Font attributes –font-family –font-weight –font-style –font-size –font-variant Text attributes –text-align –text-align-last –text-indent –start-indent –end-indent –wrap-option (defines word wrap) –break-before (defines page breaks) –break-after (defines page breaks) –reference-orientation (defines text rotation in 90" increments)

69 69 Attribute Example

70 70 Attribute Result

71 71 Lists

72 72 Tables

73 73 XSLT + FO Content Transforming using XSLT+FO

74 74 To use a.fo to generate a document in any other format use: –Apache FO processor Software Hint

75 75 Questions?


Download ppt "1 Dr Alexiei Dingli XML Technologies X-Languages."

Similar presentations


Ads by Google