CS145 Lecture Notes (5) -- XML Queries and Transformations


=> We will learn about XPath, XQuery, and XSLT, covering the most important features but ignoring many esoteric ones.


XPath

Think of XML as a tree (or directory) structure.






















XPath specifies path expressions that match XML data by navigating down (and occasionally up or across) the tree and possibly evaluating conditions over data in the tree.

Some basic constructs (very incomplete list):

/ root element, or separator between steps in path
X matches element X
* matches any element
@X matches attribute X of the current element ("context node")
// matches all descendants of the current element, including self
[C] evaluates condition C on the current element
[N] picks the Nth matching element
Path1 | Path2 union of Path1 and Path2 results
contains(s1,s2) returns TRUE if string s1 contains string s2
name() returns tag of the current element
parent:: matches the parent of the current element, if there is one
following-sibling:: matches all later siblings of the current element
descendants:: matches all descendants of the current element
self:: matches the current element

XPath inputs and results

XPath coverage



[[On-Line XPath Demo (Saxon)]]

Constructs covered:

XQuery

XQuery expression, inputs, and results

XQuery coverage



[[On-Line XQuery Demo (Saxon)]]

Constructs covered:



XSLT

XSLT expression, inputs, and results










Recursive, Rule-Based Transformation

Different "mindset" from query-answer paradigm
Main concepts:




















XSLT coverage



[[On-Line XSLT Demo (Saxon)]]

Constructs covered: