23
Multi Platform Multi Platform Applications Applications XML, XPath, XSLT XML, XPath, XSLT transform transform

Multi Platform Applications XML, XPath, XSLT transform

  • View
    244

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Multi Platform Applications XML, XPath, XSLT transform

Multi Platform ApplicationsMulti Platform Applications

XML, XPath, XSLT transformXML, XPath, XSLT transform

Page 2: Multi Platform Applications XML, XPath, XSLT transform

This WeekThis Week

XPATH – way of breaking down XML docsXPATH – way of breaking down XML docs

XML-FO – a method to format docsXML-FO – a method to format docs

XSLT – A simpler method of formatting docsXSLT – A simpler method of formatting docs

Page 3: Multi Platform Applications XML, XPath, XSLT transform

XPATHXPATH

Used to break down the structure of a XML Used to break down the structure of a XML doc and reference sectionsdoc and reference sections

The nodes of an XML document can be The nodes of an XML document can be treated as parts of a document treetreated as parts of a document tree

Page 4: Multi Platform Applications XML, XPath, XSLT transform

Nodes of an XML Nodes of an XML docdoc

document (root) nodesdocument (root) nodes

comment, comment,

processing-instruction, processing-instruction,

namespace, namespace,

text, text,

attribute, attribute,

element, element,

Page 5: Multi Platform Applications XML, XPath, XSLT transform

XML nodesXML nodes

<message><message><mail> <mail>

<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>

</mail></mail></message></message>

Node

Page 6: Multi Platform Applications XML, XPath, XSLT transform

XML relationships - XML relationships - childrenchildren

<message><message><mail> <mail>

<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>

</mail></mail></message></message>

Children of the message object

Page 7: Multi Platform Applications XML, XPath, XSLT transform

XML relationships – XML relationships – parent and siblingsparent and siblings

<message><message><mail> <mail>

<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>

</mail></mail></message></message>

Parent of the to,from, heading etc objects

These four items are siblings (same parent)

Page 8: Multi Platform Applications XML, XPath, XSLT transform

XML relationships - XML relationships - ancestorsancestors

<message><message><mail> <mail>

<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>

</mail></mail></message></message>

Ancestors of the “to” object are the mail and message object

Page 9: Multi Platform Applications XML, XPath, XSLT transform

XML relationships - XML relationships - descendantsdescendants

<message><message><mail> <mail>

<to>Patrick</to> <to>Patrick</to> <from>Mick</from> <from>Mick</from> <heading>Meeting</heading> <heading>Meeting</heading> <body>Don't forget we need to meet <body>Don't forget we need to meet tonight</body> tonight</body>

</mail></mail></message></message>

Al these are descendants of the message object

Page 10: Multi Platform Applications XML, XPath, XSLT transform

XPathXPath

Methods of selecting nodesMethods of selecting nodes

Page 11: Multi Platform Applications XML, XPath, XSLT transform

Selecting NodesSelecting Nodes

ExpressionExpression DescriptionDescription

nodenamenodename Selects all child nodes of the named nodeSelects all child nodes of the named node

// Selects from the root nodeSelects from the root node

//// Selects nodes in the document that matches Selects nodes in the document that matches the named node in the documentthe named node in the document

.. Selects the current nodeSelects the current node

.... Selects the parent of the current nodeSelects the parent of the current node

@@ Selects attributesSelects attributes

Page 12: Multi Platform Applications XML, XPath, XSLT transform

XPath addressingXPath addressing

For exampleFor example

to – to – will highlight all items called towill highlight all items called to

/message – /message – will select all items under that will select all items under that elementelement

//body//body – will select all items in the document – will select all items in the document of that nameof that name

Page 13: Multi Platform Applications XML, XPath, XSLT transform

ExpressionsExpressions

Path Expression Result

/mail/subject[1] Selects the first subject element that is the child of the mail element

/mail/subject[last()] Selects the last subject element that is the child of the mail element

/mail/subject[last()-1] Selects the last but one subject element that is the child of the mail element

/mail/subject[position()<3] Selects the first two subject elements that are children of the mail element

/mail/subject[ID>5] Selects all the subject elements of the mail element that have a ID element with a value greater than 35.00

/mail/subject[ID>5]/priority Selects all the title elements of the subject elements of the mail element that have an ID element with a value greater than 5

Page 14: Multi Platform Applications XML, XPath, XSLT transform

WildcardsWildcards

• * - Matches any element node* - Matches any element node• @* - Matches any attribute node@* - Matches any attribute node• node() -- Matches any node of any kindnode() -- Matches any node of any kind

Page 15: Multi Platform Applications XML, XPath, XSLT transform

Further ReadingFurther Reading

Look into Xpath Axes and Xpath Location Look into Xpath Axes and Xpath Location pathspaths

You can also see the operators available at You can also see the operators available at http://www.w3.org/TR/2005/WD-xpath-funhttp://www.w3.org/TR/2005/WD-xpath-functions-20050404/#op.numericctions-20050404/#op.numeric

Or Or http://www.w3schools.com/xpath/xpath_fuhttp://www.w3schools.com/xpath/xpath_functions.aspnctions.asp

Page 16: Multi Platform Applications XML, XPath, XSLT transform

XLink and XpointerXLink and Xpointer

XLink - XML Linking Language XLink - XML Linking Language

XLink is a language for creating hyperlinks XLink is a language for creating hyperlinks in XML documents in XML documents

XLink is similar to HTML links - but more XLink is similar to HTML links - but more powerful powerful

Not limited to images and text - any element Not limited to images and text - any element in an XML document can behave as an in an XML document can behave as an XLink XLink

Page 17: Multi Platform Applications XML, XPath, XSLT transform

Xlinks 2Xlinks 2

XLink has two grouping of linksXLink has two grouping of links

simple links (like HTML) and simple links (like HTML) and

extended links (for linking multiple extended links (for linking multiple resources) resources)

With XLink, the links can be defined With XLink, the links can be defined externally to the linked resourcesexternally to the linked resources

XLink is a W3C StandardXLink is a W3C Standard

Page 18: Multi Platform Applications XML, XPath, XSLT transform

XPointerXPointer

XPointer - XML Pointer Language XPointer - XML Pointer Language

XPointer allows hyperlinking to specific parts XPointer allows hyperlinking to specific parts of an XML document of an XML document

XPointer uses XPath expressions to XPointer uses XPath expressions to navigate the position in an XML document navigate the position in an XML document

XPointer is a W3C Standard XPointer is a W3C Standard

Page 19: Multi Platform Applications XML, XPath, XSLT transform

Simple XlinkSimple Xlink

<?xml version="1.0"?> <?xml version="1.0"?>

<homepages xmlns:xlink="http://www.w3.org/1999/xlink"> <homepages xmlns:xlink="http://www.w3.org/1999/xlink">

<homepage xlink:type="simple" <homepage xlink:type="simple" xlink:href="http://www.bolton.ac.uk">Visit Bolton</homepage> xlink:href="http://www.bolton.ac.uk">Visit Bolton</homepage>

<homepage xlink:type="simple" <homepage xlink:type="simple" xlink:href="http://www.bbc.co.uk">BBC</homepage> xlink:href="http://www.bbc.co.uk">BBC</homepage>

</homepages> </homepages>

Page 20: Multi Platform Applications XML, XPath, XSLT transform

Pointing with PathsPointing with Paths

Remember the CD catalog exampleRemember the CD catalog example

How would we pick out an artist from that How would we pick out an artist from that XML file?XML file?

We can point not just to a file but to an area We can point not just to a file but to an area of a file e.g.of a file e.g.

href="http://www.bolton.ac.uk/href="http://www.bolton.ac.uk/catalog.xml#disc(‘Hits').child(1,item)" catalog.xml#disc(‘Hits').child(1,item)"

Page 21: Multi Platform Applications XML, XPath, XSLT transform

XMLXML

<?xml version="1.0" encoding="ISO-8859-1"?><?xml version="1.0" encoding="ISO-8859-1"?><collection><collection> <disc <disc title = “Hits” id = “Hits“>title = “Hits” id = “Hits“> <artist>Five</artist><artist>Five</artist> <country>UK</country><country>UK</country> <company>Telstar</company><company>Telstar</company> <price>4.99</price><price>4.99</price> <year>2003</year><year>2003</year> </disc></disc>....</collection></collection>

Page 22: Multi Platform Applications XML, XPath, XSLT transform

Xpointer and linksXpointer and links

xlink:href="http://www.bolton.ac.uk/xlink:href="http://www.bolton.ac.uk/catalog.xml#xpointer(id(‘Hits'))"catalog.xml#xpointer(id(‘Hits'))"

You can use a shorter version when linking You can use a shorter version when linking to an element with an id tag. You can use to an element with an id tag. You can use the value of the id directly, like this: the value of the id directly, like this: http://www.bolton.ac.uk/catalog.xml#Hithttp://www.bolton.ac.uk/catalog.xml#Hits"s"

Page 23: Multi Platform Applications XML, XPath, XSLT transform

Useful LinksUseful Links

http--http--www.topxml.com-tutorials-sqlxml-sqlxml.pwww.topxml.com-tutorials-sqlxml-sqlxml.pdfdf

SQL Server 2000 and XML Part 6 - AnnotatSQL Server 2000 and XML Part 6 - Annotated XDR Schemes Free Tutorial ed XDR Schemes Free Tutorial

Beginners.co.ukBeginners.co.uk