XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Advanced XSLT. Branching in XSLT XSLT is functional programming –The program evaluates a function –The function transforms one structure into another.
Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
XML: Extensible Markup Language
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSL XSLT and XPath 11-Apr-17.
+ XSL eXtensible Stylesheet Language. + 2 XML Lecture Adapted from the work of Prof Mark Baker ACET, University of Reading.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)
1 XSL – XML Stylesheet Language. 2 XSL XSL = XML Stylesheet Language XSL cosists of –XPath (navigation in documents) –XSLT (T for transformations) –XSLFO.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
Rendering XML documents with XSL The most powerful approaches to rendering XML documents involve using XSL (eXtensible Stylesheet Language) XSL enables.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
XSL Unit 6 November 2. XSL –eXtensible Stylesheet Language –Basically a stylesheet for XML documents XSL has three parts: –XSLT –XPath –XSL-FO.
A note on generating text with the xsl:value-of instruction.
1 Copyright (c) [2000]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents Roger L. Costello XML Technologies.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
1 XPATH Modified Slides from Dr. Sagiv. 2 XPath A Language for Locating Nodes in XML Documents XPath expressions are written in a syntax that resembles.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
XSLT XSLT: eXtensible Stylesheet Language for Transformations - a language for transforming XML documents into any text- based format (e.g. HTML, plain.
ECA 228 Internet/Intranet Design I Intro to XSL. ECA 228 Internet/Intranet Design I XSL basics W3C standards for stylesheets – CSS – XSL: Extensible Markup.
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.
1 cs XSL XSL is a standard that consists of three parts: XPath (navigation in documents) XPath was taught in the DB course, so it will not be.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
CIS 375—Web App Dev II XSL. 2 XSL Introduction XSL stands for _____________________________. XSL is the language used for manipulating and displaying.
Lecture 11 XSL Transformations (part 1: Introduction)
XPath Aug ’10 – Dec ‘10. XPath   XML Path Language   Technology that allows to select a part or parts of an XML document to process   XPath was.
 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 – XSL: Extensible Stylesheet Language Transformations (XSLT) Outline 12.1Introduction 12.2Setup.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Applying eXtensible Style Sheets (XSL) Ellen Pearlman Eileen Mullin Programming.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
1 cs XSL XSL is a standard that consists of three parts: XPath (navigation in documents) XPath was taught in the DB course, so it will not be.
1 XML Data Management Extracting Data from XML: XPath Werner Nutt based on slides by Sara Cohen, Jerusalem.
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
Unit 3 — Advanced Internet Technologies Lesson 11 — Introduction to XSL.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
1 XPath Extracting Data from XML. 2 Data stored in an XML document must be extracted to use with various applications Data can be extracted programmatically.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
XML Schema – XSLT Week 8 Web site:
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
Lecture Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
CH 15 XSL Transformations 1. Objective What is XSL? Overview of XSL transformations Understanding XSL templates Computing the value of a node with xsl:value-of.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
Session IV Chapter 14 – Chapter 14 – XSLThttp://
Unit 4 Representing Web Data: XML
Displaying XML Data with XSLT
Chapter 7 Representing Web Data: XML
Modified Slides from Dr. Sagiv
Modified Slides from Dr. Sagiv
Presentation transcript:

XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA V (b). XML Querying: XSLT December 2005

Outline  Introduction  XML Basics  XML Structural Constraint Specification  Document Type Definitions (DTDs)  XML Schema  XML/Database Mappings  XML Parsing APIs  Simple API for XML (SAX)  Document Object Model (DOM)  XML Querying and Transformation  XPath  XSLT  XQuery  XML Applications

XSL (eXtensible Stylesheet Language) XSL is a high-level functional language used to transform XML documents into various formats (XML, HTML etc.) XSL program consists of a set of TEMPLATE rules. Each rule consists of a pattern and a template. –Pattern (XPath expression) => where clause template => construct clause –XSL processor starts from the root element and tries to apply a pattern to that node; If it succeeds, it executes the corresponding template. –The template, when executed, usually instructs the processor to produce some XML result and to apply the templates –Recursively on the node's children. An XSL style sheet is a valid XML document

Dark Side of the Moon Pink Floyd Space Oddity David Bowie 9.90 Aretha: Lady Soul Aretha Franklin 9.90 Dark Side of the Moon Pink Floyd Space Oddity David Bowie 9.90 Aretha: Lady Soul Aretha Franklin 9.90 An XML document

Applying XSLT Stylesheets to XML Documents There are three ways of applying an XSLT stylesheet to an XML document: Directly applying an XSLT processor to the XML document and the XSLT stylesheet Calling an XSLT processor from within a (Java) program Adding to the XML document a link to the XSL stylesheet and letting the browser do the transformation

Using an XSL Processor XSL Processor XML document XML document XSL stylesheet XSL stylesheet Result is either an XML, HTML or text document Result is either an XML, HTML or text document java org.apache.xalan.xslt.Process -IN myXmlFile.xml -XSL myXslFile.xsl -OUT myOutputFile.html Directly applying the Xalan XSL processor

Letting a Browser Perform the Transformation <?xml-stylesheet type="text/xsl" href=“catalog.xsl"?> Dark Side of the Moon Pink Floyd … <?xml-stylesheet type="text/xsl" href=“catalog.xsl"?> Dark Side of the Moon Pink Floyd … A link to the stylesheet

The Root of the XSL Document (program) The Root of the XSL document should be one of the following lines: <xsl:stylesheet version="1.0" xmlns:xsl=" <xsl:transform version="1.0" xmlns:xsl=" The namespace allows the XSL processor to distinguish between XSL tags and tags of the result document

How Does XSLT Work? An XSL stylesheet is a collection of templates that are applied to source nodes (i.e., nodes of the given XML document) Each template has a match attribute that specifies to which source nodes the template can be applied The current source node is processed by applying a template that matches this node Processing always starts at the root (/)

Templates A template has the form... Template content... The content of a template consists of –XML elements and text (HTML etc) that are copied to the result –XSL elements that are actually instructions The pattern syntax is a subset of XPath

<xsl:stylesheet version="1.0" xmlns:xsl=" Transform"> Hello World <xsl:stylesheet version="1.0" xmlns:xsl=" Transform"> Hello World Single Template XSL program

Applying a browser to catalog.xml (catalog.xml has a link to catalog.xsl) Hello World

Processing starts by applying a template that matches the root (/) –If the given XSL stylesheet does not have a template that matches the root, then one is inserted by default (“Default Templates”) The XSL stylesheet must specify explicitly whether templates should be applied to descendants of the root It is done by putting inside a template the instruction: Without the select attribute, this instruction processes all the children of the current node The XSL Element

<xsl:stylesheet version="1.0" xmlns:xsl=" A CD! <xsl:stylesheet version="1.0" xmlns:xsl=" A CD! A CD!

Default Templates XSL provides implicit built-in templates that match every element and text nodes Templates we write always override these built-in templates (when they match)

<xsl:stylesheet version="1.0" xmlns:xsl=" Hello World <xsl:stylesheet version="1.0" xmlns:xsl=" Hello World Interaction of Default and User Defined Templates

Dark Side of the Moon Pink Floyd Hello World Aretha: Lady Soul Aretha Franklin 9.90 This is printed by the template from the previous slide The default templates print the text in the leaves of the first and third cd’s

The Most Frequently Used Elements of XSL –This element extracts the value of a node from the nodelist located by xpath-expression –This element loops over all the nodes in the nodelist located by xpath-expression,, etc. –This element is for conditional processing

The Element The XSL element can be used to extract the value of an element that is selected from the source XML document The extracted value is added to the output stream The selected element is located by an XPath expression that appears as the value of the select attribute

Selected values Example of Element Suppose we want to produce the above web page from the XML file.

<xsl:stylesheet version="1.0" xmlns:xsl=" Transform"> A CD Catalog Title Artist <xsl:stylesheet version="1.0" xmlns:xsl=" Transform"> A CD Catalog Title Artist

<xsl:value-of select="catalog/cd/title"/> <xsl:value-of select="catalog/cd/artist"/> <xsl:value-of select="catalog/cd/title"/> <xsl:value-of select="catalog/cd/artist"/> Note that only the first matched element is retrieved for each

The Element The element loops over all the nodes in the nodelist of the XPath expression that appears as the value of the select attribute The value of each node can be extracted by an element

All the values are selected Suppose we want to produce the above web page from the XML file. Example of Element

<xsl:stylesheet version="1.0" xmlns:xsl=" A CD Catalog Title Artist <xsl:stylesheet version="1.0" xmlns:xsl=" A CD Catalog Title Artist As in the previous example

Note that all the /catalog/cd elements are retrieved

<xsl:for-each select="catalog/cd[price <xsl:for-each select="catalog/cd[price Only elements that satisfy /catalog/cd[price<10] are retrieved Consider the following change in the select attribute:

Suppose we want to produce the above web page from the XML file. The Element

The element is used to sort the list of nodes that are looped over by the element Thus, the must appear inside the element The looping is done in sorted order

Sorted by the name of the artist Example of Element

The /catalog/cd elements are sorted according to the value of the artist element

The Element The element is used for conditional processing The condition appears as the value of the test attribute, for example: 10"> some output... The elements inside the element are processed if the condition is true. Processing the inside elements means –Copying them into the output stream if they are not XSL elements, and –Evaluating them if they are XSL elements If the value of the test attribute is just an XPath expression (i.e., without any comparison), then the test is satisfied if the nodelist of this XPath expression is not empty

<xsl:stylesheet version="1.0" xmlns:xsl=" Transform"> A CD Catalog Title Artist <xsl:stylesheet version="1.0" xmlns:xsl=" Transform"> A CD Catalog Title Artist As in the previous examples Example of Element

10"> 10"> Only /catalog/cd with price>10 are retrieved

Applying Templates Recursively The following example shows how to apply templates recursively Generally, it is possible (but not in this example) that more than one template matches the current source node The specification ( describes (Section 5.5) which template should be chosen for applicationwww.w3.org/TR/xslt

<xsl:stylesheet version="1.0" xmlns:xsl=" A CD Catalog <xsl:stylesheet version="1.0" xmlns:xsl=" A CD Catalog

Title: Title:

Artist: Artist:

Is Recursive Application of Templates Really Needed? The output of the previous example can also be generated by an XSL stylesheet that uses only one template that matches the root (and does not use the element ) However, some tasks can only be done by applying templates recursively –This typically happens when the structure of the source XML document is not known

Recursive Template Application Suppose that we want to write an XSL stylesheet that generates an exact copy of the source XML document –It is rather easy to do it when the structure of the source XML document is known Can we write an XSL stylesheet that does it for every possible XML document? –Yes!

<xsl:stylesheet xmlns:xsl=" version="1.0"> Identity Transformation Stylesheet

Summary XSLT is a high-level transformation language Create core output once in XML format (using Servlets, JSP, etc.) Use XSLT to transform the core output as needed