13-xml

13-xml - 1 XSLT CPS 116 Introduction to Database Systems 2...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 XSLT CPS 116 Introduction to Database Systems 2 Announcements (Tue. Oct. 25) ¡ Homework #3 due in 1½ weeks ¡ Project milestone #2 due in 2½ weeks 3 XSLT ¡ XML-to-XML rule-based transformation language ¢ Used most frequently as a stylesheet language ¢ An XSLT program is an XML document itself ¢ Current version is 2.0; W3C recommendation since January 2007 XSLT processor XSLT program Input XML Output XML Actually, output does not need to be in XML in general 4 XSLT program ¡ An XSLT program is an XML document containing ¢ Elements in the <xsl:> namespace ¢ Elements in user namespace ¡ The result of evaluating an XSLT program on an input XML document = the XSLT document where each <xsl:> element has been replaced with the result of its evaluation ¡ Basic ideas ¢ Templates specify how to transform matching input nodes ¢ Structural recursion applies templates to input trees recursively ¡ Uses XPath as a sub-language 5 XSLT elements ¡ Element describing transformation rules ¢ <xsl:template> ¡ Elements describing rule execution control ¢ <xsl:apply-templates> ¢ <xsl:call-template> ¡ Elements describing instructions ¢ <xsl:if> , <xsl:for-each> , <xsl:sort> , etc. ¡ Elements generating output ¢ <xsl:value-of> , <xsl:attribute> , <xsl:copy- of> , <xsl:text> , etc. 6 XSLT example ¡ Find titles of books authored by “Abiteboul” <?xml version=“1.0”?> <xsl:stylesheet xmlns:xsl=“http://www.w3.org/1999/XSL/Transform” version=“2.0”> <xsl:template match=“book[author=‘Abiteboul’]”> <booktitle> <xsl:value-of select=“title”/> </booktitle> </xsl:template> </xsl:stylesheet> ¡ Not quite; we will see why later Standard header of an XSLT document 2 7 <xsl:template> <xsl:template match=“book[author=‘Abiteboul’]”> <booktitle> <xsl:value-of select=“title”/> </booktitle> </xsl:template> ¡ <xsl:template match=“ match_expr ”> is the basic XSLT construct describing a transformation rule ¢ match_expr is an XPath-like expression specifying which nodes this rule applies to ¡ <xsl:value-of select=“ xpath_expr ”/> evaluates xpath_expr within the context of the node matching the template, and converts the result sequence to a string ¡ <booktitle> and </booktitle> simply get copied to the output for each node match 8 Template in action <xsl:template match=“book[author=‘Abiteboul’]”> <booktitle> <xsl:value-of select=“title”/> </booktitle> </xsl:template> ¡ Example XML fragment <book ISBN=”ISBN-10” price=”80.00”> <title>Foundations of Databases</title> <author>Abiteboul</author> <author>Hull</author>...
View Full Document

This document was uploaded on 01/17/2012.

Page1 / 4

13-xml - 1 XSLT CPS 116 Introduction to Database Systems 2...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online