XSLT program. XSLT elements. XSLT example. An XSLT program is an XML document containing

Similar documents
XSLT. Announcements (October 24) XSLT. CPS 116 Introduction to Database Systems. Homework #3 due next Tuesday Project milestone #2 due November 9

XML-XQuery and Relational Mapping. Introduction to Databases CompSci 316 Spring 2017

Semi-structured Data 11 - XSLT

XML and Databases XSLT Stylesheets and Transforms

Extensions to XSLT 1.0, and XSLT 2.0

Author: Irena Holubová Lecturer: Martin Svoboda

Introduction to XSLT. Version 1.3 March nikos dimitrakas

Extensible Markup Stylesheet Transformation (XSLT)

Introduction to XSLT. Version 1.0 July nikos dimitrakas

XML. Objectives. Duration. Audience. Pre-Requisites

XSL Transformation (XSLT) XSLT Processors. Example XSLT Stylesheet. Calling XSLT Processor. XSLT Structure

XSLT: How Do We Use It?

Computer Science E-259

EXAM XML 1.1 and Related Technologies TYPE: DEMO

SAX & DOM. Announcements (Thu. Oct. 31) SAX & DOM. CompSci 316 Introduction to Database Systems

Exam : Title : XML 1.1 and Related Technologies. Version : DEMO

XML, DTD, and XPath. Announcements. From HTML to XML (extensible Markup Language) CPS 116 Introduction to Database Systems. Midterm has been graded

Manipulating XML Trees XPath and XSLT. CS 431 February 18, 2008 Carl Lagoze Cornell University

Lars Schmidt-Thieme, Information Systems and Machine Learning Lab (ISMLL), University of Hildesheim, Germany, Course on XML and Semantic Web

XSL extensible Style Language" DOCUMENTS MULTIMEDIA! Transforming documents using! XSLT" XSLT processor" XSLT stylesheet"

XPath and XSLT. Overview. Context. Context The Basics of XPath. XPath and XSLT. Nodes Axes Expressions. Stylesheet templates Transformations

XPath and XQuery. Introduction to Databases CompSci 316 Fall 2018

XQuery. Announcements (March 21) XQuery. CPS 216 Advanced Database Systems

Semi-structured Data: Programming. Introduction to Databases CompSci 316 Fall 2018

XML. Rodrigo García Carmona Universidad San Pablo-CEU Escuela Politécnica Superior

XML and Databases. Lecture 11 XSLT Stylesheets and Transforms. Sebastian Maneth NICTA and UNSW

Oracle Application Server 10g Oracle XML Developer s Kit Frequently Asked Questions September, 2005

XML and Databases. Outline XML. XML, typical usage scenario XML. 1. extensible Stylesheet Language X M L. Sebastian Maneth NICTA and UNSW

INTERNET & WEB APPLICATION DEVELOPMENT SWE 444. Fall Semester (081) Module 4 (III): XSL

Semantic Web. XSLT: XML Transformation. Morteza Amini. Sharif University of Technology Fall 95-96

info-h-509 xml technologies Lecture 5: XSLT Stijn Vansummeren February 14, 2017

XML and Semantic Web Technologies. II. XML / 5. XML Stylesheet Language Transformations (XSLT)

Introduction to XSLT

XSL Elements. xsl:copy-of

XML: Extensible Markup Language

XSLT is... XML XSLT XSL-FO XPath

XSLT Programming Constructs

XML and XSLT. XML and XSLT 10 February

XML. <subtitle>xslt (cont)</subtitle> <author>prof. Dr. Christian Pape</author>

XML-Relational Mapping. Introduction to Databases CompSci 316 Fall 2014

Comp 336/436 - Markup Languages. Fall Semester Week 9. Dr Nick Hayward

XML Wrap-up. CS 431 March 1, 2006 Carl Lagoze Cornell University

Birkbeck (University of London)

Computer Science E-259

Advanced XSLT. Web Data Management and Distribution. Serge Abiteboul Ioana Manolescu Philippe Rigaux Marie-Christine Rousset Pierre Senellart

Advanced XSLT. Web Data Management and Distribution. Serge Abiteboul Philippe Rigaux Marie-Christine Rousset Pierre Senellart

Extreme Java G Session 3 - Sub-Topic 5 XML Information Rendering. Dr. Jean-Claude Franchitti

JSON & MongoDB. Introduction to Databases CompSci 316 Fall 2018

Appendix H XML Quick Reference

XSLT (part II) Mario Alviano A.Y. 2017/2018. University of Calabria, Italy 1 / 19

Web Data Management XSLT. Philippe Rigaux CNAM Paris & INRIA Saclay

<xsl:apply-templates select="atom:entry/atom:content"/> <xsl:copy-of xmlns:xsl="

Presentation. Separating Content and Presentation Cascading Style Sheets (CSS) XML and XSLT

XSLT. December 16, 2008

COP 4814 Florida International University Kip Irvine XSLT. Updated: 2/9/2016 Based on Goldberg, Chapter 2. Irvine COP 4814

Section A: Multiple Choice

XSLT (part I) Mario Alviano A.Y. 2017/2018. University of Calabria, Italy 1 / 22

XSLT. Lecture 38. Robb T. Koether. Mon, Apr 21, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XSLT Mon, Apr 21, / 26

Advanced XSLT editing: Content query web part (CQWP) Dolev Raz SharePoint top soft Soft.co.il

COPYRIGHTED MATERIAL. Contents. Part I: Introduction 1. Chapter 1: What Is XML? 3. Chapter 2: Well-Formed XML 23. Acknowledgments

Burrows & Langford Appendix D page 1 Learning Programming Using VISUAL BASIC.NET

Introduction to XSLT

XSL Languages. Adding styles to HTML elements are simple. Telling a browser to display an element in a special font or color, is easy with CSS.

The Transformation Language XSL

Style Sheet A. Bellaachia Page: 22

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Querying transformed XML documents: Determining a sufficient fragment of the original document

XSLT Version 2.0 is Turing-Complete: A Purely Transformation Based Proof

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

A PROTOTYPE FOR TRANSLATING XSLT INTO XQUERY

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 7 XML

CSI 3140 WWW Structures, Techniques and Standards. Representing Web Data: XML

XSLT. Patryk Czarnik. XML and Applications 2014/2015 Lecture

XPath and XSLT without the pain!

The Transformation Language XSL

XSL and OU Campus. OmniUpdate User Training Conference OmniUpdate, Inc Flynn Road, Suite 100 Camarillo, CA 93012

Querying and Transforming XML Data Chapter5 Contents

XSL Concepts: Conditions and Loops. Robert Kiffe, Senior Web Developer OmniUpdate, Inc.

Special Session: Semantic Gossiping. 2003/4, Karl Aberer, EPFL-SSC, Laboratoire de systèmes d'informations répartis Semantic Gossiping - 1

MASTER OF SCIENCE THESIS

7.1 Introduction. extensible Markup Language Developed from SGML A meta-markup language Deficiencies of HTML and SGML

Translating XSLT into XQuery

Next Generation Query and Transformation Standards. Priscilla Walmsley Managing Director, Datypic

4. Unit: Transforming XML with XSLT

Presentation 19: XML technologies part 2: XSL, XSLT, XSL-FO, XPath & XML Programming

EXAM IN SEMI-STRUCTURED DATA Study Code Student Id Family Name First Name

<xsl:variable name="g_ndstemplatedoc" select="document($g_strhtmltemplatename)"/>

Generating Variants Using XSLT Tutorial

Introduction to Database Systems CSE 414

INFO/CS 4302 Web Informa6on Systems

Structured documents

EXtensible Markup Language (XML) a W3C standard to complement HTML A markup language much like HTML

COMP9321 Web Application Engineering

WebSphere DataPower SOA Appliances and XSLT (Part 2 of 2) - Tips and Tricks

Transcript of Abel Braaksma's Talk on XSLT Streaming at XML Prague 2014

Introduction to Database Systems CSE 444

Advanced XQuery and XSLT

xmlns:gu=" xmlns:uky="

Developing High-Quality XSLT Stylesheets

Dynamic Indexing with XSL

Transcription:

XSLT CPS 216 Advanced Database Systems Announcements (March 24) 2 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 XSLT 3 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 program XSLT processor Input XML Output XML Actually, output does not need to be in XML in general

XSLT program 4 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 Uses XPath as a sub-language XSLT elements 5 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:copyof>, <xsl:text>, etc. XSLT example 6 Find titles of books authored by Abiteboul <?xml version= 1.0?> Standard header of an XSLT document <xsl:stylesheet xmlns:xsl= http://www.w3.org/1999/xsl/transform version= 2.0 > <booktitle> <xsl:value-of select= title /> </booktitle> </xsl:stylesheet> Not quite; we will see why later

<xsl:template> 7 <booktitle> <xsl:value-of select= title /> </booktitle> <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 Template in action 8 <booktitle> <xsl:value-of select= title /> </booktitle> Example XML fragment <book ISBN= ISBN-10 price= 80.00 > <title>foundations of Databases</title> <author>abiteboul</author> <author>hull</author> <author>vianu</author> <publisher>addison Wesley</publisher> <year>1995</year> <section> </section> </book> <book ISBN= ISBN-20 price= 40.00 > <title>a First Course in Databases</title> <author>ullman</author> <author>widom</author> <publisher>prentice-hall</publisher> <year>2002</year> <section> </section> </book> Template applies <booktitle> Foundations of Databases </booktitle> Template does not apply; default behavior is to process the node recursively and print out all text nodes A First Course in Databases Ullman Widom Prentice-Hall 2002 Removing the extra output 9 Add the following template: <xsl:template match= text() @* /> This template matches all text and attributes XPath features text() is a node test that matches any text node @* matches any attribute means or in XPath Body of the rule is empty, so all text and attributes become empty string This rule effectively filters out things not matched by the other rule

<xsl:attribute> 10 Again, find titles of books authored by Abiteboul ; but make the output look like <book title= booktitle /> <book title= {normalize-space(title)} /> A more general method <book> <xsl:attribute name= title > <xsl:value-of select= normalize-space(title) /> </xsl:attribute> </book> <xsl:attribute name= attr >body</xsl:attribute> adds an attributed named attr with value body to the parent element in the output <xsl:copy-of> 11 Another slightly different example: return (entire) 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= text() @* /> <xsl:copy-of select=. /> </xsl:stylesheet> <xsl:copy-of select= xpath_expr /> copies the entire contents (including tag structures) of the node-set returned by xpath_expr to the output Formatting XML into HTML 12 Example templates to Render a book title in italics in HTML Render the authors as a comma-separated list <xsl:template match= book/title > <i><xsl:value-of select= normalize-space(.) /></i> <xsl:template match= book/author[1] > <xsl:value-of select= normalize-space(.) /> <xsl:template match= book/author[position()>1] > <xsl:text>, </xsl:text> <xsl:value-of select= normalize-space(.) /> <xsl:text> allows precise control of white space in output

<xsl:apply-templates> 13 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 <xsl:template match= title > <xsl:value-of select= normalize-space(.) /> <xsl:template match= section > <li> <xsl:apply-templates select= title /> <ol><xsl:apply-templates select= section /></ol> </li> (Continue on next slide) <xsl:apply-templates select= xpath_expr /> applies templates recursively to the node-set returned by xpath_expr Example continued 14 <xsl:template match= book > <li> <xsl:apply-templates select= title /> <ol><xsl:apply-templates select= section /></ol> </li> <xsl:template match= bibliography > <html> <head><title>bibliography</title></head> <body> <ul><xsl:apply-templates select= book /></ul> </body> </html> One problem remains Even if a book or a section has no sections, we will still generate an empty <ol></ol> element <xsl:if> 15 A fix using <xsl:if>: replace <ol><xsl:apply-templates select= section /></ol> with <xsl:if test= section > <ol><xsl:apply-templates select= section /></ol> </xsl:if> The body of <xsl:if test= xpath_cond > is processed only if xpath_cond evaluates to true

White space control 16 White space is everywhere in XML <book ISBN= ISBN-10 price= 80.00 > tt<title> ttttfoundations of Databases tt</title> tt goes into a text node ttttfoundations of Databases tt goes into another text node Specify <xsl:strip-space elements= * /> to remove text nodes (under any element) containing only white space To strip leading and trailing white space and replace any sequence of white space characters by a single space, specify <xsl:template match= text() > <xsl:value-of select= normalize-space() /> <xsl:for-each> 17 <xsl:for-each select= xpath_expr > body </xsl:for-each> Process body for each node in the node-set returned by xpath_expr Processing context changes to the node being processed Another way to render authors as a comma-separated list <xsl:tempalte match= book > <xsl:for-each select= author > <xsl:if test= position()>1 >, </xsl:if> <xsl:value-of select= normalize-space(.) /> </xsl:for-each> Named templates with parameters 18 Define a generic template for rendering a list of things as a comma-separated list Cannot use match because we do not know in advance the things to render <xsl:template name="comma-separated-list"> <xsl:param name="things-to-be-formatted"/> <xsl:for-each select="$things-to-be-formatted"> <xsl:if test="position()>1">, </xsl:if> <xsl:value-of select= normalize-space(.)"/> </xsl:for-each>

19 Calling templates & passing parameters Use the generic template <xsl:template match="book"> <xsl:value-of select= normalize-space(title)"/> <xsl:text>: </xsl:text> <xsl:call-template name="comma-separated-list"> <xsl:with-param name="things-to-be-formatted select="author"/> </xsl:call-template> <br/> <xsl:with-param name= para_name select= xpath_expr > evaluates xpath_expr and passes its result as the value of the parameter para_name <xsl:call-template> invokes the named template without changing the context XSLT summary 20 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! Review 21 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 22 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