Download XSLT: Transforming XML with XSLT Templates and Rules and more Slides Database Management Systems (DBMS) in PDF only on Docsity!
XSLT
CPS 216
Advanced Database Systems
2
Announcements (March 24)
Homework #3 will be assigned next Tuesday
Reading assignment due next Wednesday
XML processing in Lore ( VLDB 1999) and Niagara
( VLDB 2003)
Project milestone 2 due next Thursday
3
XSLT
XML-to-XML rule-based transformation language
An XSLT program is an XML document itself
Used most frequently as a stylesheet language
Version 1.0 a W3C recommendation
Version 2.0 under development together with XPath 2.
XSLT processor
XSLT program
Input XML Output XML Actually, output does not need to be in XML in general
XSLT program
An XSLT program is an XML document containing
Elements in the namespace
Elements in user namespace
The result of evaluating an XSLT program on an
input XML document =
the XSLT document where each element
has been replaced with the result of its evaluation
Uses XPath as a sub-language
5
XSLT elements
Element describing transformation rules
Elements describing rule execution control
Elements describing instructions
, , , etc.
Elements generating output
, , , , etc.
6
XSLT example
Find titles of books authored by “Abiteboul”
Not quite; we will see why later
Standard header of an XSLT document
Again, find titles of books authored by “Abiteboul”; but
make the output look like
… …
… …
A more general method
… …
… …
body adds an attributed named attr with value body to the parent element in the output
11
Another slightly different example: return (entire) books
authored by “Abiteboul”
copies the entire
contents (including tag structures) of the node-set returned
by xpath_expr to the output
12
Formatting XML into HTML
Example templates to
Render a book title in italics in HTML Render the authors as a comma-separated list
1]”> ,
allows precise control of white space in output
Example: generate a table of contents
Display books in an HTML unordered list For each book, first display its title, and then display its sections in an HTML ordered list For each section, first display its title, and then display its subsections in an HTML ordered list
(Continue on next slide)
applies templates recursively to the node-set returned by xpath_expr
14
Example continued
Bibliography
One problem remains
Even if a book or a section has no sections, we will still generate an empty element
15
A fix using : replace
with
The body of is
processed only if xpath_cond evaluates to true
Calling templates & passing parameters
Use the generic template
:
evaluates xpath_expr and passes its
result as the value of the parameter para_name
invokes the named template
without changing the context
20
XSLT summary
Used often as a stylesheet language, but can be
considered a query language too
Very expressive, with full recursion
- Cannot be replaced by XQuery?
- Well, XQuery actually support user-defined functions, which can be recursive
Easily non-terminating, difficult to optimize
So many features, so little time! ☺
21
Review
XML: tree (or graph)-structured data
DTD: simple schema for XML
Well-formed XML: syntactically correct Valid XML: well-formed and conforms to a DTD
XPath: path expression language for XML
An XPath expression selects a list of nodes in an XML document Used in other languages
XQuery: SQL-like query language for XML
FLWOR expression, quantified expression, aggregation, etc.
XSLT: stylesheet language for XML, in XML
Transforms input XML by applying template rules recursively on the structure of input XML
XML API’s
SAX (Simple API for XML)
Started out as a Java API, but now exists for other languages too Streaming input; callbacks for events (start/end of document and elements, chunk of characters, etc.)
DOM (Document Object Model)
Language-neutral API with implementations in Java, C ++, etc. Converts input into a main-memory tree; supports tree traversal, construction, and in-place modification
JAXB (Java Architecture for XML Binding)
XML Schema to Java objects