Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.

Slides:



Advertisements
Similar presentations
Inside an XSLT Processor Michael Kay, ICL 19 May 2000.
Advertisements

XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
Multimedia Seminar XSLT Tobias Naumann. MM Seminar - XSLT2 Structure What is XSLT? Design and Concepts Practical use Examples.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
Internet Technologies1 1 Lecture 4: Programming with XSLT.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : XSLT.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSLT (eXtensible Stylesheet Language Transformation) 1.
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.
XML and XSL Transforming your XML documents with eXtensible Stylesheet Language Transformations [Optional Lecture]
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
Extensible Stylesheet Language (XSL) By Example Tony Wat 9 October 2002.
XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)
Rendering XML documents with XSL The most powerful approaches to rendering XML documents involve using XSL (eXtensible Stylesheet Language) XSL enables.
Processing XML Processing XML using XSLT Processing XML documents with Java (DOM) Next week -- Processing XML documents with Java (SAX)
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
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.
Internet Technologies XSLT Processing XML using XSLT Using XPath Escaping to Java.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
Object Oriented Programming III1 XSLT Processing XML using XSLT Using XPath.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Internet Technologies1 XSLT Processing XML using XSLT Using XPath.
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.
Technical Track Session XML Techie Tools Tim Bornholt.
Using XSLT and XPath to Enhance HTML Documents Reference: Roger L. Costello
XSLT Part 3B. id() The id() function returns a node-set containing the node or nodes with a given ID attribute. An ID attribute in this context is any.
XSLT XSLT: eXtensible Stylesheet Language for Transformations - a language for transforming XML documents into any text- based format (e.g. HTML, plain.
10/06/041 XSLT: crash course or Programming Language Design Principle XSLT-intro.ppt 10, Jun, 2004.
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
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.
Comparing XSLT and XQuery Michael Kay XTech 2005.
XSL XML Stylesheet Langauage. XPath Notation for addressing elements in an XML document /xyz - selects the root element /xyz/abc - selects all elements.
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,
Transforming XML Part II XML Document Transformation with XSLT John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
Lecture 14 Extensible Stylesheet Language Transformations : XSLT.
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 "
Extensible Stylesheet Language Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University XSL-FO XSLT.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
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)
 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.
ITB Web programming for E- Commerce 1 ITB6227 Programming for E-COMMERCE Lecture Presentation of XML Documents.
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.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
Dr. Chunbo Chu Week 3. XML Not a replacement for HTML. XML and HTML were designed with different goals: XML was designed to transport and store data,
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
XSLT Design Patterns.
1 XMLXSL(T) and CSS NOEA/PQC (rev. fen) 2007 Stylesheets CSS:Cascading Style Sheets XSL(T):eXtended Stylesheet Language (Transformations)
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
Lecture 15 Extensible Stylesheet Language Transformations : XSLT.
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.
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.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations
CS 431 – February 28, 2005 Carl Lagoze – Cornell University
XSL XSLT and XPath.
Unit 6 - XML Transformations
Presentation transcript:

Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha

Goals Understand the basics of the XSLT transformation language, its design patterns and uses. Learn how to transform an xml instance into html page(s). And finally learn how to generate formatting objects using transformations with XSLT and render those objects into a pdf representation. We will use our catalog example to create an html representation first. The next session will deal with generating pdf files.

XSLT Primer XSLT is a declarative and functional language used to transform source trees into result trees XSLT works on node trees not on documents In XSLT you cannot change variables once they are set – there are no side effects XSLT processing is unpredictable with respect to order of processing Creating an XSLT rule file called „Stylesheet“ is not much like programming. It can be used in a template like mode where it fills in the blanks. Or it can be used to specify rules which are applied when the source document is transformed into the node tree which becomes input for XSLT processing.

<xsl:stylesheet xmlns:xsl=" xmlns:doc=" exclude-result-prefixes="doc„ version='1.0'> (The template rule) Catalog (literal result elements) Catalog (xsl instructions generating nodes) The structure of an XSLT Stylesheet A xsl template matches nodes from the document input tree and performs operations on those nodes. Literal elements are just copied over into the result node tree.

How an XSLT processor works The XSLT processer lets an XML parser transform the source document into the source tree consisting of nodes. It reads the stylesheet (rule) file and applies its rules to the source node tree, thereby transforming it into a result node tree. This tree is then serialized in whatever output format is requested. This processing can be changed because the result can be just another xml document, ready for input to a new XSLT transformation process with a different style sheet. This is not unlike SQL works with database tables as Michael Kay notes from whom this diagram comes. (see Resources) Style Sheet HTML Instance Source Tree Parser Style tree Result Tree XML Text Serialization Transformation Process

How to use an XSLT processor java -classpath ".;D:/xmltools/saxon.jar;" com.icl.saxon.StyleSheet -o catalog.html catalog.xml catalog.xsl I am using the saxon xslt processor, a pure java implementation by Michael Kay. Alternatives are the Xalan processor from apache.org. Internet Explorer can also perform xslt transformation directly. Here –o catalog.html directs the processor to create an output file with the name catalog.html and to use catalog.xml as the input document and catalog.xsl as the stylesheet containing the transformation rules.

Important XSLT directives Defines a template rule which will be processed when the processor finds a node that matches „somePattern“ in the source node tree. Selectively (if select is defined) continues processing of child nodes of the current node. copy the text from the source nodes matching somePattern over into the result tree. XPath expressions to address selects an articleNumber attribute from a child node with name „article“ of the current node. Some of the expressions can become quite complicated, depending on the structure of the source document, the target (result structure) and the amount of transformation necessary. It makes a difference if e.g. the result tree is very close in structure to the source tree.

Step one: understand how your xml instance is structured We seem to have two blocks in our instance which look a little like they could be represented as tables: Article and Producer. Table of content Page Numbers ?? IndexArticlesOrder Form Catalog Article Article Data PriceLegalProducerDescriptionPictureArticle Number 1 ? + * PhoneContactLocationNameLogoQuantityRebate ArticleRef Term ** + * 1 * Delivery 1

Step two: define your result tree Article Header Article Description complete producer information in table form main article data in table form Legal statements delivery information Pictures and technical data You will notice that the target structure differs from the source structure in several places. Where there is NO difference we will use the so called rule-based processing with XSLT. If the order changes, we will use the „fill-in-the-blanks“ pattern to selectively pull in content from the source tree into our result tree. And just in case the result tree needs a lot of processing we will use the „navigational pattern“ which uses subroutine calls between template rules and is closest to regular programming. Terms after M.Kay who also mentions another pattern: computational stylesheets.

Step three: create stylesheet template The header is standard but the rest is for debugging ONLY! It will show elements with no matching rule in red in the result tree so you know what you have missed yet. No template matches. < > </ >

Step four: apply simple rules For those elements which we want to copy over from the source tree into the result tree we just create xsl:template match=... comands, surrounded by html literals e.g. to create a header or an image link. Order Form Index

Step five: fill in the blanks The column values for our producer table are pulled in with xsl:value-of and a pattern to select. This makes our stylesheet independent of source document changes (e.g. order of producer child elements) Producer information list name location phone contact stock

Step six: run the XSLT processor

Resources (1) Michael Kay, XSLT 2nd Edition, Programmers Reference Charles Goldfarb, XML Handbook 4 th edition: read about XSLT.