XSLT: Using XML to transform other XML files What is XSLT? XSLT ...

103 downloads 108 Views 410KB Size Report
What is XSLT? • An XML-based style sheet language for XML documents. – Tells web browser how to display data. – Similar to CSS for HTML, but with absolute ...
What is XSLT?

2

• An XML‐based style sheet language for XML  documents

XSLT: Using XML to transform  other XML files

– Tells web browser how to display data – Similar to CSS for HTML, but with absolute control over input

• Achieves similar results to XQuery – Pro: supported by all non‐ancient web browsers – Con: XML syntax is [really] verbose

Introduction to databases CSC343 Fall 2011 Ryan Johnson Thanks to Manos Papagelis, John Mylopoulos, Arnold Rosenbloom and Renee Miller for material in these slides

XSLT processing model • The XSLT processing model involves: – – – –

one (or more) XML source documents one (or more) XSLT style sheet modules the XSLT template processing engine one (or more) result documents

• XSLT is most often used to  – convert data between different XML schemas   – to convert XML data into web pages (HTML)

3

XSLT vs XQUERY

4

• XSLT capabilities overlap with XQuery – same data model, type system, function library – both include XPath 2.0 as a sublanguage

• Rooted in different traditions and communities – XSLT: primarily conceived as a stylesheet language  – XQuery: primarily conceived as a database query language

• When to use: – XSLT: stronger in its handling of narrative documents with  more flexible structure – XQuery: stronger in its data handling (e.g, when performing  relational joins)

1

Example 1: Transform. XML to HTML Empire Burlesque Bob Dylan USA Columbia 10.90 1985 … Unchain my heart Joe Cocker USA EMI 8.20 1987

5

7

The HTML Result Document

My CD Collection Title

Artist

Empire Burlesque

Bob Dylan





Unchain my heart

Joe Cocker

6

The XSLT for the XML

My CD Collection

template for doc root ... top‐level content here   ... named template  (for explicit instantiation) more template content here

Sample: root node template

24

Elements template applies to HTML to embed the template in Instantiate show‐tree template, passing e=*  and i=0 as parameters By default, output the   , (surrounded by parens,    ) separated by commas) recursively apply  template to children


Sample XSLT + clinical_study XML HTML Output

26

Rendered HTML

required_header