Transforming Data to Information - XSLT XPath and XQuery


CSS allows us to produce an XML file with style attributes. XSLT and XPath allow us to completely transform the contents of the file into anything else - including anything we would like to present.

xslt information flow

XSLT is a declarative and functional programming language

The syntax and semantics are structured for processing XML

XPath allows us to navigate within an XML document - a hierarchy

For example, we may wish to select an element if a contraint is fulfilled: select the people who have mobile phones

While XSLT uses XPath to navigate around an XML hierarchy, XML Query is an SQL like query language that uses XPath to extract elements from databases and return them as XML.

Example: To retrieve all the mobile phone numbers for W3C:

for $a in document("AllAddresses.xml")/Team
let $b:=$a/@file
for $c in $b=>//Addresses/Person[Tel/@where='mobile']
return
<dt>{$c/Name}</dt>
<dd>{$c/Tel[@where='mobile']}</dd>

The result can be XML or any XML application (e.g. XHTML) - many of which are designed for presentation.