750 likes | 769 Views
Explore X.Link, X.Pointer, X.Path, X.Query, X.Form, XSLT, and FO in XML for powerful link definition, resource access, navigation, data querying, form creation, and stylesheet transformations. Learn how to leverage X technologies effectively.
E N D
XML Technologies X-Languages
Contents • X Link • X Pointer • X Path • X Query (Brief) • X Form (Brief) • XSLT • FO
X Languages X Query XPointer XLink X Path XSLT
X Link • 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 Syntax • 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 Explanation • 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"
Advanced X Links • 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
X Pointer • XML Pointer Language • Allow hyperlinks to point to specific parts of an XML document • Uses XPath for navigation
X Pointer Example • 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 Short Hand href="http://www.example.com/cdlist.xml#id('rock') Is equivalent to href="http://www.example.com/cdlist.xml#rock
X Path • 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 Nodes • Element • Attribute • Text • Namespace • Processing-instruction (<?xml version="1.0"?>) • Comment • Root node
Node relationships • Parent • Children • Siblings • Ancestors • Descendants
Example <?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>
Location step • 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]
Absolute vrs Relative An absolute location path: /step/step/... A relative location path: step/step/... The difference is the initial /
Programming example xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("books.xml"); xpath="/bookstore/book[1]/title"; xmlDoc.selectNodes(xpath);
X Query • Designed to query XML Data • Like SQL for databases • Built on XPath
XQuery Example doc("books.xml")/bookstore/book/title Load the document and use XPath to get the data For more powerful queries use FLWOR expressions
X Forms • Similar to HTML forms but defined in XML • Richer and more flexible • Platform and device independent • Standard in XHTML 2.0
X Forms Result • The form • The XML • The Text
XSL • XML Stylesheet Language • Consist of three parts • XSLT • Xpath • XSL-FO
XSLT • XSL Transformations • Transforms XML to another XML document • Uses XPath to navigate • Most important part of XSL • Supported by most browsers
Power • Add • Remove • Sort • Rearrange • Perform Tests • Make decisions • Hide • Etc ...
Workings • Use XPath to define elements of source • When a match occurs • Transform the matching part into the resulting document
Example 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"?>
Declaration part of a Stylesheet <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template> • 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