Advanced XSLT. Branching in XSLT XSLT is functional programming –The program evaluates a function –The function transforms one structure into another.

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

Inside an XSLT Processor Michael Kay, ICL 19 May 2000.
XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
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.
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.
Internet Technologies1 1 Lecture 4: Programming with XSLT.
XSLT 11-Apr-17.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSL XSLT and XPath 11-Apr-17.
XML: Managing Data Exchange Stylesheets. Lesson Contents CSS The basic XSL file XSL transforms Templates Sort Numbering Parameters and Variables Datatypes.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)
Processing XML Processing XML using XSLT Processing XML documents with Java (DOM) Next week -- Processing XML documents with Java (SAX)
XSL Transformations (XSLT) Meghasyam Bokam April’1 st, 2002.
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.
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
1 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Using Extension Elements and Extension Functions with XSLT and XPath Roger L. Costello.
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.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XSLT and XPath, by Dr. Khalil1 XSL, XSLT and XPath Dr. Awad Khalil Computer Science Department AUC.
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
Extensible Markup and Beyond
E0262 – MIS – Multimedia Storage Techniques XML (Extensible Markup Language)  XML is a markup language for creating documents containing structured information.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Module Road Map Credit Categories Assignment 2 Credit Category 2 You are able to demonstrate how data may be filtered using Xpath You are able to demonstrate.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
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 part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter X IXXXXXXXXXX XXXXXX.
Lecture 11 XSL Transformations (part 1: Introduction)
XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs.
An OO schema language for XML SOX W3C Note 30 July 1999.
 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 – XSL: Extensible Stylesheet Language Transformations (XSLT) Outline 12.1Introduction 12.2Setup.
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.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
XP 1 XSLT II Robin Burke ECT 360. XP 2 Outline Conditionals Numbering Functions and operators Variables and parameters Named and recursive templates.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
XP 1 XSLT II Robin Burke ECT 360. XP 2 Homework #4 Forgot we hadn't covered "choose" becomes extra credit My books.xml didn't include descriptions.
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
XML Extensible Markup Language
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.
Chapter X IXXXXXXXXXXXXXXXX.
CS 431 – February 28, 2005 Carl Lagoze – Cornell University
More XML XML schema, XPATH, XSLT
EXTENDING COMPONENTS AND TABLE TRANSFORMATIONS WITH XSL
Presentation transcript:

Advanced XSLT

Branching in XSLT XSLT is functional programming –The program evaluates a function –The function transforms one structure into another –The function is written in XML The transform flow can branch depending on the content Similar idea to an if statement in OOP

The if element allows the transform to branch It contains further processing instructions Branching is controlled by a Boolean attribute called test if test has value true, the transform branches through the content of if

Boolean Values test is an XML attribute of if –its value is an XPath expression –this will be interpreted as a Boolean standard rules apply to translate the results of XPath expressions to Booleans XPath typically evaluates to the following types: –number, node set, string

translation to Boolean values Number +0 or -0 or NaN false, all other numbers true node-set –empty node-set false, non-empty node-set true String –empty string false, all other strings true true() and false() functions

True or false? - always true - returns false - true if and only if non-empty node-set - depends on number of zones examples

example Some XML data contains zone elements If the number of zone elements is greater than 2, we wish to produce some HTML A template for zone has been predefined We will use if to decide whether to transform the zone elements into HTML

<!the following instructions are processed if and only if the number of zone elements in the current context is greater than 2 --> Applicable Zones example

Example - notes We have a separate template for zone This can be developed separately from the if transform An XSLT can be built up from different parts Use templates to divide your transform into easy-to-program steps

Branching in XSLT Several nested if elements become difficult to program The choose element plays the role of a case statement in XSLT The transform will branch into one of a choice of transforms depending on the value of an XPath expression

contains one or more elements –when operates exactly like if –test attribute with Boolean XPath value –content is further transform instructions choose may contain one optional otherwise element –represents the default case –content is further transform instructions

example we will define an attribute value using choose the attribute will be a bgcolor for table rows we want the rows to alternate between orange and green we use the position() function in an XPath expression for our test

orange green

example - notes the attribute element can be used to define an attribute during the transform –can be inserted in output – see later the text element is used to precisely define literal text content the example again relies on pre-defined templates for other elements (the content of zone)

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 by an XPath expression we use a for-each element to control the iteration

Applies processing to all nodes in a given node set select attribute contains XPath expression defining the node set the current node changes at each iteration of for-each –changes the context for transforms of content

example we have XML data for a tutorial, divided into sections we wish to produce a numbered contents list in HTML we use for-each twice to create a numbered heading and a list of sections we use the position() function for the numbering

XML Tutorial XML and DTDs XPath and XSLT The Data

Section 1. XML Tutorial 1. XML and DTDs 2. XPath and XSLT … and so on for each section The Desired Output

Section.. </xsl:template

example - notes for-each select=section selects all section nodes in the current tutorial –position() will number the sections in document order for-each select=panel selects all panel nodes in the current section this is just a nested loop!

modes Sometimes you may wish to transform the same node in more than one way The transform for a node is defined in a template A mode attribute is available for template and apply-templates elements This allows more than one template to be defined for any node

example XML data for a famous scientists website The data contains a name element for each person featured on the site. We use mode to achieve two different presentations of name –table of contents –personal data entry

Alan Turing computer scientist mathematician cryptographer The Data

Richard P Feynman physicist playing the bongoes The Data

The Desired Output Turing, Alan Feynman, Richard Name: Alan Turing Born: 1912 Died: 1954 Professions: computer scientist, mathematician, cryptographer Hobbies: none known

<xsl:stylesheet version = 1.0 xmlns:xsl= > Famous Scientists <xsl:apply-templates select = person mode = toc />

,

Name: Born: Died:

attribute value templates allows attribute values derived from the source to be set in the output example <name first = {first_name} initial = {middle_initial} last = {last_name} />

specifies a particular template to be invoked perhaps not related directly to a node-set –e.g. to add boilerplate start_html markup template must have a name attribute calls the template by name

<!Interesting stuff that generates the masthead goes in here --> … some-title

, defines parameters for templates parameters can be passed to templates from either call-template or apply-template elements containing elements name attribute names the parameter select attribute (or content) defines the value of the parameter

XSLT processing flow reference to template and parameter passed return to XSLT processing flow

150 …

allows values to be stored to assist with processing flow logic name attribute names the variable select attribute (or content) defines the value of the variable value can also be defined from element content

, $y = 13 else $y = 15 -->

appears inside or inside sorts a node-set according to some criterion successive sort elements impose sub-orders select attribute defines the sorting criterion data-type defines the type of sort –text (the default) –number

more sort attributes order –ascending (default) –descending case-order –upper-first –lower-first

document ( ) converts a parameter into a URI –relative to current document –second parameter gives an alternative base URI returns a node-set associated with the URI allows content to be extracted from multiple XML documents without parameter defaults to current document

multiple XML files XSLT document XSLT processor output document set of template rules match elements and replace using template rules XML source XML source XML source XML source XML source XML source master document document()

Fridge Contents XML XSLT

XSLT extensions extension elements are passed to external code (extension functions) for processing –Java, Perl, C# etc. extends power of XSLT to arbitrary transformations implementation varies between XSLT processors –Xalan, Saxon, XT all allow extensions, but in different ways