1 Dr Alexiei Dingli XML Technologies X-Languages.
-
Upload
ronald-reed -
Category
Documents
-
view
219 -
download
2
Transcript of 1 Dr Alexiei Dingli XML Technologies X-Languages.
1
Dr Alexiei Dingli
XML Technologies
X-Languages
2
• X Link
• X Pointer
• X Path
• X Query (Brief)
• X Form (Brief)
• XSLT
• FO
Contents
3
X Languages
X Query XPointer XLink
X Path
XSLT
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
• In HTML we use the <A> tag
• In XML all tags can have a link
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage
xlink:type="simple" xlink:href="http://www.um.edu.mt">
University of Malta
</homepage>
</homepages>
X Link Syntax
6
• Declare the namespace in the top element<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
• 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
• 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
• XML Pointer Language
• Allow hyperlinks to point to specific parts of an XML document
• Uses XPath for navigation
X Pointer
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 5th item in the list
X Pointer Example
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
• 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
• Element
• Attribute
• Text
• Namespace
• Processing-instruction (<?xml version="1.0"?>)
• Comment
• Root node
X Path Nodes
13
• Parent
• Children
• Siblings
• Ancestors
• Descendants
Node relationships
14
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
Example
15
Expression Description
nodename Selects 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
Path Expression Result
bookstore Selects all the child nodes of the bookstore element
/bookstore Selects the root element bookstoreNote: If the path starts with a slash ( / ) it always represents an absolute path to an element!
bookstore/book Selects all book elements that are children of bookstore
//book Selects all book elements no matter where they are in the document
bookstore//book Selects all book elements that are descendant of the bookstore element, no matter where they are under the bookstore element
//@lang Selects all attributes that are named lang
Examples
17
Path Expression Result
/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]/title Selects 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
Wildcard Description
* Matches any element node
@* Matches any attribute node
node() Matches any node of any kind
Using Wildcards
Path Expression Result
/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
Path Expression Result
//book/title | //book/price Selects all the title AND price elements of all book elements
//title | //price Selects all the title AND price elements in the document
/bookstore/book/title | //price Selects all the title elements of the book element of the bookstore element AND all the price elements in the document
Selecting several paths
20
AxisName Result
ancestor Selects all ancestors (parent, grandparent, etc.) of the current node
ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself
attribute Selects all attributes of the current node
child Selects all children of the current node
descendant Selects all descendants (children, grandchildren, etc.) of the current node
descendant-or-self Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself
following Selects everything in the document after the closing tag of the current node
following-sibling Selects all siblings after the current node
namespace Selects all namespace nodes of the current node
parent Selects the parent of the current node
preceding Selects everything in the document that is before the start tag of the current node
preceding-sibling Selects all siblings before the current node
self Selects the current node
Axes
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
Example Result
child::book Selects all book nodes that are children of the current node
attribute::lang Selects 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::book Selects all book descendants of the current node
ancestor::book Selects all book ancestors of the current node
ancestor-or-self::book Selects all book ancestors of the current node - and the current as well if it is a book node
child::*/child::price Selects all price grandchildren of the current node
Location step example
23
An absolute location path:
/step/step/...
A relative location path:
step/step/...
The difference is the initial /
Absolute vrs Relative
24
Operator Description Example Return value
| Computes two node-sets //book | //cd Returns a node-set with all book and cd elements
+ Addition 6 + 4 10
- Subtraction 6 - 4 2
* Multiplication 6 * 4 24
div Division 8 div 4 2
= Equal price=9.80 true if price is 9.80false if price is 9.90
!= Not equal price!=9.80 true if price is 9.90false if price is 9.80
< Less than price<9.80 true if price is 9.00false if price is 9.80
<= Less than or equal to price<=9.80 true if price is 9.00false if price is 9.90
> Greater than price>9.80 true if price is 9.90false if price is 9.80
>= Greater than or equal to price>=9.80 true if price is 9.90false if price is 9.70
or or price=9.80 or price=9.70 true if price is 9.80false if price is 9.50
and and price>9.00 and price<9.90 true if price is 9.80false if price is 8.50
mod Modulus (division remainder) 5 mod 2 1
25
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("books.xml");
xpath="/bookstore/book[1]/title";
xmlDoc.selectNodes(xpath);
Programming example
26
• Designed to query XML Data
• Like SQL for databases
• Built on XPath
X Query
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
• Similar to HTML forms but defined in XML
• Richer and more flexible
• Platform and device independent
• Standard in XHTML 2.0
X Forms
29
X Forms Example
30
• The form
• The XML
• The Text
X Forms Result
31
• XML Stylesheet Language
• Consist of three parts– XSLT– Xpath– XSL-FO
XSL
32
• XSL Transformations
• Transforms XML to another XML document
• Uses XPath to navigate
• Most important part of XSL
• Supported by most browsers
XSLT
33
• Add
• Remove
• Sort
• Rearrange
• Perform Tests
• Make decisions
• Hide
• Etc ...
Power
34
• Use XPath to define elements of source
• When a match occurs– Transform the matching part into the resulting
document
Workings
35
CD Catalogue (XML)
CD Catalogue (XSL)
CD Catalogue (XML + XSL)
Combined by adding the following line in the XML document<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
Example
36
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
Declaration part of a Stylesheet
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
<xsl:template>
38
Simple Template 1
39
Simple Template 1 Result
40
Simple Template 2
41
Simple Template 2 Result
42
Simple Template 3
43
Simple Template 3 Result
44
Simple Template 4
45
Simple Template 4 Result
46
Simple Template 5
47
Simple Template 5 Result
48
Simple Template 6
49
Simple Template 6 Result
50
Simple Template 7
51
Simple Template 7 Result
52
Simple Template 8
53
Simple Template 8 Result
54
• Script to transform using Java Script and XSLT
From the Client Side
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
• 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
Example FO
58
< Root
^ Namespace
< One or more page template
< Page
content
Explanation
59
• Pages (Contain many regions)
• Regions (Contain Block Areas)
• Block Areas (Contain Line Areas)
• Line Areas (Contain Inline Areas)
• Inline Areas
Areas
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
Page Regions
62
Page Example
63
• Blocks flow into pages
Flow
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
Block Area
66
<fo:page-sequence>
<fo:flow flow-name="xsl-region-body"> <fo:block>
<!-- Output goes here -->
</fo:block>
</fo:flow>
</fo:page-sequence>
Block Example
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
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
Attribute Example
70
Attribute Result
71
Lists
72
Tables
73
XSLT + FOC
on
ten
tC
on
ten
tT
ran
sfo
rmin
g u
sin
g X
SL
T+
FO
Tra
nsf
orm
ing
usi
ng
XS
LT
+F
O
74
• To use a .fo to generate a document in any other format use:
– Apache FO processor
Software Hint
75
Questions?