XSLT: Transforming XML with XSLT Templates and Rules, Slides of Database Management Systems (DBMS)

An introduction to xslt (extensible stylesheet language transformations), a language used for transforming xml documents into other formats such as xml, html, or plain text. Xslt programs consist of templates and rules that describe how to transform input xml into output xml. The basics of xslt, including xslt processors, xslt elements, and examples of xslt templates. It also discusses how to use xslt to extract specific information from xml documents, such as finding titles of books authored by a specific author.

Typology: Slides

2011/2012

Uploaded on 01/28/2012

arold
arold 🇺🇸

4.7

(24)

372 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
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.0
XSLT processor
XSLT program
Input XML Output XML
Actually, output does not need to be in XML in general
pf3
pf4
pf5
pf8

Partial preview of the text

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

  • Cannot replace XQuery

™ 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