XSLT and Structural Recursion. Gestão e Tratamento de Informação DEI IST 2011/2012

Similar documents
Author: Irena Holubová Lecturer: Martin Svoboda

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

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

Semi-structured Data 11 - XSLT

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

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

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

Introduction to Database Systems CSE 444

Introduction to Data Management CSE 344

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

10/24/12. What We Have Learned So Far. XML Outline. Where We are Going Next. XML vs Relational. What is XML? Introduction to Data Management CSE 344

Computer Science E-259

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

Introduction to Database Systems CSE 414

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.

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

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

Section A: Multiple Choice

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

XML. Objectives. Duration. Audience. Pre-Requisites

XPath an XML query language

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

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

Introduction to Semistructured Data and XML. Overview. How the Web is Today. Based on slides by Dan Suciu University of Washington

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

Introduction to Semistructured Data and XML

Computer Science E-259

516. XSLT. Prerequisites. Version 1.2

Style Sheet A. Bellaachia Page: 22

EXAM XML 1.1 and Related Technologies TYPE: DEMO

XSL Elements. xsl:copy-of

Introduction to XSLT. Version 1.0 July nikos dimitrakas

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

Extensible Markup Stylesheet Transformation (XSLT)

Querying XML Data. Querying XML has two components. Selecting data. Construct output, or transform data

Introduction to Database Systems CSE 414

Gestão e Tratamento de Informação

XML, XPath, and XSLT. Jim Fawcett Software Modeling Copyright

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

XML and XSLT. XML and XSLT 10 February

Data Formats and APIs

The XML Query Language Xcerpt: Design Principles, Examples, and Semantics

XML Query Languages. Yanlei Diao UMass Amherst April 22, Slide content courtesy of Ramakrishnan & Gehrke, Donald Kossmann, and Gerome Miklau

Introduction to XML. Yanlei Diao UMass Amherst April 17, Slides Courtesy of Ramakrishnan & Gehrke, Dan Suciu, Zack Ives and Gerome Miklau.

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

xmlns:gu=" xmlns:uky="

XSLT: How Do We Use It?

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

XML. XML Namespaces, XML Schema, XSLT

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

CSE-6490B Final Exam

Sample Relational Database

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

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

Functions & Conditional Statements

Evaluating XPath Queries

XML and Databases XSLT Stylesheets and Transforms

The Transformation Language XSL

Introduction to Semistructured Data and XML. Management of XML and Semistructured Data. Path Expressions

Querying and Transforming XML Data Chapter5 Contents

Applied Databases. Sebastian Maneth. Lecture 18 XPath and XSLT. University of Edinburgh - March 23rd, 2017

Introduction to XML (Extensible Markup Language)

INLS 760 Web Databases Lecture 12 XML, XPATH, XSLT

Burrows & Langford Chapter 9 page 1 Learning Programming Using Visual Basic.NET

Additional Readings on XPath/XQuery Main source on XML, but hard to read:

Introduction p. 1 An XML Primer p. 5 History of XML p. 6 Benefits of XML p. 11 Components of XML p. 12 BNF Grammar p. 14 Prolog p. 15 Elements p.

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

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

Display the XML Files for Disclosure to Public by Using User-defined XSL Zhiping Yan, BeiGene, Beijing, China Huadan Li, BeiGene, Beijing, China

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

XML. COSC Dr. Ramon Lawrence. An attribute is a name-value pair declared inside an element. Comments. Page 3. COSC Dr.

4. Unit: Transforming XML with XSLT

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

Introduction to XSLT. Version 1.3 March nikos dimitrakas

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

The main Topics in this lecture are:

XPath and XSLT without the pain!

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 27-1

XML in Databases. Albrecht Schmidt. al. Albrecht Schmidt, Aalborg University 1

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

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

Hypermedia and the Web XSLT and XPath

XML Overview, part 1

8/1/2016. XSL stands for EXtensible Stylesheet Language. CSS = Style Sheets for HTML XSL = Style Sheets for XML. XSL consists of four parts:

DocBook: A Case Study and Anecdotes. Norman Walsh Sun Microsystems, Inc.

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

4. Unit: Transforming XML with XSLT

Traditional Query Processing. Query Processing. Meta-Data for Optimization. Query Optimization Steps. Algebraic Transformation Predicate Pushdown

The Transformation Language XSL

XML: Extensible Markup Language

Extensions to XSLT 1.0, and XSLT 2.0

SDPL : XML Basics 2. SDPL : XML Basics 1. SDPL : XML Basics 4. SDPL : XML Basics 3. SDPL : XML Basics 5

Introduction to Database Systems CSE 414

CS145 Final Examination

The XML Metalanguage

XSLT XML. Incremental Maintenance of Materialized XML Views Defined by XSLT DEWS2004 I-5-04

$Q,QFUHPHQWDO;6/77UDQVIRUPDWLRQ3URFHVVRU IRU;0/'RFXPHQW0DQLSXODWLRQ

H2 Spring B. We can abstract out the interactions and policy points from DoDAF operational views

XML Applications. Prof. Andrea Omicini DEIS, Ingegneria Due Alma Mater Studiorum, Università di Bologna a Cesena

AFew existing languages transforming XML data into

Transcription:

XSLT and Structural Recursion Gestão e Tratamento de Informação DEI IST 2011/2012

Outline Structural Recursion The XSLT Language

Structural Recursion : a different paradigm for processing data Data is modeled through sets and there is also a set union operator: {a:3, a:{b: one, c:5}, b:4} = {a:3} U {a:{b: one,c:5}} U {b:4} Data are processed by applying functions recursively over the structure (I.e., over the sets)

An Example Find all integer values in the data f($t1 U $T2) = f($t1) U f($t2) f({$l: $T}) = f($t) f({}) = {} f($v) = if isint($v) then {result: $V} else {} a a b 3 b c 4 one 5 result result result 3 5 4

Another Example What does the following program do? f($t1 U $T2) = f($t1) U f($t2) f({$l: $T}) = if $L=a then {b:f($t)} else {$L:f($T)} f({}) = {} f($v) = $V

Yet Another Example Increase engine prices by 10% f($t1 U $T2) = f($t1) U f($t2) f({$l: $T}) = if $L= engine then {$L: g($t)} else {$L: f($t)} f({}) = {} f($v) = $V g($t1 U $T2) = g($t1) U g($t2) g({$l: $T}) = if $L= price then {$L:1.1*$T} else {$L: g($t)} g({}) = {} g($v) = $V engine body engine body part price part price part price part price price 100 1000 price 100 1000 price 110 1100 price 100 1000

General form for structural recursion programs f 1 ($T1 U $T2) = f 1 ($T1) U f 1 ($T2) f 1 ({$L: $T}) = E 1 ($L, f 1 ($T),...,f k ($T), $T) f 1 ({}) = { } f 1 ($V) = g($v).... f k ($T1 U $T2) = f k ($T1) U f k ($T2) f k ({$L: $T}) = E k ($L, f 1 ($T),...,f k ($T), $T) f k ({}) = { } f k ($V) = g($v) Each E 1,..., E k consists only of {_ : _}, U, if_then_else_

Outline Structural Recursion The XSLT Language

The W3C XSL Standard The XSL standard is composed of: A language for expressing XML transformations (XSLT) An XML vocabulary for specifying formating semantics: XSL-FO (formatting objects) An XSLT program expresses a transformation from one XML document into a result tree: Another XML document An HTML document A document that contains FO XSL-FO in general: Corresponds to one or more screen areas or pages Has properties to describe the visual aspect of the area(s) Contains contents in the form of: text external objects (image, applet, etc.), or Additional formatting objects

XSLT Programs XSL program = template-rule... template-rule template-rule = match pattern + template Computation Model: Different from other query languages. XSL begins in the root element and tries to apply a pattern to ther node. If it succeeds, then it executes the corresponding template over the node. Normally, the template includes XSLT instructions for producing the XML result tree, or for applying templates recursively over the child nodes. In the last case, the process is repeated. Thus, he XSLT program is like a recursive function.

XSLT Template Rules The template rules are indicated by elements of the type xsl:template The matching pattern is specifyed through an XPath in the value for the match attribute The actual template is the content for the xsl:template element <xsl:apply-templates/> is an instruction that applies the entire XSLT program to all the descentants of the matched element

An Example XML Document <bib> </bib> <book> </book> <paper> </paper> <book> </book> <title> t1 </title> <author> a1 </author> <author> a2 </author> <title> t2 </title> <author> a3 </author> <author> a4 </author> <title> t3 </title> <author> a5 </author> <author> a6 </author> <author> a7 </author>

Example XSLT Program <xsl:template match = * > <xsl:apply-templates/> <xsl:template match = title > <result> <xsl:value-of select =. /> </result> Results: <result> t1 </result> <result> t2 </result> <result> t3 </result> <xsl:template match="text()">

How the program works It starts by the root <bib>... </bib> Checks if any pattern matches the root node The pattern from the first template is satisfied. XSLT evaluates the body of the template, which contains <xsl:apply-templates/> This implies that the entire program is going to be applied to all descendants of the <bib> element Once again, the pattern from the first template is satisfied This implies that the entire program is going to be applied to the elements <title> and <author> Finallty, the pattern for the second template is satisfied by the element <title> The XSLT program generates a <result>...</result> element in which the content is the value for the current node, i.e. The textual string with the title

XSLT Patterns: Path Expressions bib the bib element * any element / root /bib bib element under the root bib/paper paper element, child from bib bib//paper paper child from bib, at any depth //paper paper element at any depth paper book paper or book element @price price attribute bib/book/@price price attribute in book, from bib db/book[@price] books having a price attribute db/book[@price= 10 ] books with a price equal to 10

Using <xsl:element name= X > Creates a new element named X Example: <xsl:template match= A > <xsl:element name = B > <xsl:value-of select =. /> <xsl:element/> The above example is equivalent to: <xsl:template match= A > <B><xsl:value-of select =. /></B>

Another Example <xsl:template match= * > <xsl:element name = {name()} > <xsl:value-of select =. /> </xsl:element> Copies all top-level elements from the entry document name() returns the name for the current node, and we use this string as the name for the output node.

Another XSLT Program... <xsl:template match = * > <xsl:apply-templates/> <xsl:template match= a > <A><xsl:apply-templates/></A> <xsl:template match= b > <B><xsl:apply-templates/></B> <xsl:template match= c > <C><xsl:value-of select=. /></C>

...Applied to a Document <a> <e> <b> <c> 1 </c> <c> 2 </c> </b> <a> <c> 3 </c> </a> </e> <c> 4 </c> </a> <A> <B> <C> 1 </C> <C> 2 </C> </B> <A> <C> 3 </C> </A> <C> 4 </C> </A>

Conflict resolution for template matching rules If several template rules match, choose the one with the highest priority Priorities can either be: Explicit : <xsl:template match= abc priority= 1.41 > Implicit : ad-hoc rules given by W3C, based on the match match= abc priority 0. match= [... some namespace name... ] priority -0.25. match= node() priority -0.5.

XSLT and Structural Recursion Equivalent to: f(t1 U T2) = f(t1) U f(t2) f({l: T}) = if L= c then {C: t} else L= b then {B: f(t)} else L= a then {A: f(t)} else f(t) f({}) = {} f(v) = V <xsl:template match= c > <xsl:template match= b > <xsl:template match= a > <xsl:template match = * >

XSLT versus Structural Recursion The XSLT Language: Operates on trees Program can create an infinite loop Structural Recursion: Over arbitrary graphs Programs always terminate

Example : Converting XML to HTML <xsl:template match= / > <HTML> <HEAD> <TITLE> Bibliography entries </TITLE> </HEAD> <BODY> <xsl:apply-templates/> </BODY> </HTML> <xsl:template match= title > <TD> <xsl:value-of select=. /> </TD> <xsl:template match= author > <TD><xsl:value-of select=. /></TD> <xsl:template match = book paper > <TR> <xsl:apply-templates select= title /> <xsl:apply-templates select= author /> </TR> <xsl:template match= bib > <TABLE> <TBODY> <xsl:apply-templates/> </TBODY> </TABLE>

HTML Result <HTML> <HEAD> <TITLE> Bibliography Entries </TITLE> </HEAD> <BODY> <TABLE> <TBODY> <TR><TD> t1 </TD> <TD> a1 </TD> <TD> a2 </TD> </TR> <TR><TD> t2 </TD> <TD> a3 </TD> <TD> a4 </TD> </TR> <TR><TD> t3 </TD> <TD> a5 </TD> <TD> a6 </TD> <TD> a7 </TD></TR> </TBODY> </TABLE> </BODY> </HTML>

Yet Another Simple XSLT Copies the entry document: <xsl:template match = / > <xsl:apply-templates/> <xsl:template match = {text()} > <xsl:value-of select=. /> <xsl:template match = * > <xsl:element name= name() > <xsl:apply-templates/> </xsl:element>

Exercise Write an XSLT program that transforms the XML document: <teaches> <teaches-tuple course="xml" lecturer="peter Wood"/> <teaches-tuple course="algorithms" lecturer="trevor Fenner"/> </teaches> Into another XML document with the following general schema: <teaches> <teaches-tuple> <course>xml</course><lecturer>peter Wood</lecturer> </teaches-tuple> <teaches-tuple> <course>algorithms</course><lecturer>trevor Fenner</lecturer> </teaches-tuple> </teaches>

References S. Abiteboul, P. Buneman, D. Suciu, Data on the Web, From Relations to Semistructured Data and XML, Morgan Kaufmann, 2000, (caps 5 e 6) Peter Wood, Slides on Representing and Querying Data on the Web, http://www.dcs.bbk.ac.uk/~ptw/teaching/data-on-the-web.html. Dan Suciu, Slides on The semistructured data model, CSE 590ds: Management of XML and Semistructured Data, http://www.cs.washington.edu/education/courses/cse590ds/01sp/ www.w3.org/style/xsl/ W3C's XSL home page nwalsh.com/docs/tutorials/xsl/ an XSL tutorial by Paul Grosso and Norman Walsh metalab.unc.edu/xml/books/bible/updates/14.html a chapter from the XML Bible on XSL Transformations (and XPath)

Questions? Gestão e Tratamento de Informação DEI IST 2011/2012