SDPL 2002Notes 5.1: Additional XPath & XSLT1 5.1 Additional features of XPath & XSLT n XPath support for –arithmetical operations –processing ID/IDREF.

Slides:



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

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.
Internet Technologies1 1 Lecture 4: Programming with XSLT.
XML: Managing Data Exchange Stylesheets. Lesson Contents CSS The basic XSL file XSL transforms Templates Sort Numbering Parameters and Variables Datatypes.
SDPL 2003Notes 5.1: Additional XPath & XSLT1 5.1 Additional features of XPath & XSLT n XPath support for –arithmetical operations –processing ID/IDREF.
SDPL 2011XSLT: Additional features & Computing1 4.1 Additional XSLT Features n XPath for arithmetics, cross-references, and string manipulation n Generating.
SDPL 2005Notes 5.1: Additional XPath & XSLT1 5.1 Additional features of XPath & XSLT n XPath support for –arithmetics –processing ID/IDREF cross-references.
XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)
XSL Transformations (XSLT) Meghasyam Bokam April’1 st, 2002.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
Lecture 15. Repetition In essence, repetition is already built into the default processing provided by every XSLT processor –the default processing for.
A note on generating text with the xsl:value-of instruction.
XML Workshop XSLT. XML Tagged data Hello A really interesting course, well taught Interchange of data RSS, BPEL4WS, RossettaNet … Structure document representation.
XSL Transformations Lecture 8, 07/08/02. Templates The whole element is a template The match pattern determines where this template applies Result element(s)
XPath Carissa Mills Jill Kerschbaum. What is XPath? n A language designed to be used by both XSL Transformations (XSLT) and XPointer. n Provides common.
XPath Tao Wan March 04, What is XPath? n A language designed to be used by XSL Transformations (XSLT), Xlink, Xpointer and XML Query. n Primary.
CS 4408 Lecture 9. XSLT instruction elements We have seen that a template can contain non-XSLT text, canned text that it inserts into the result tree.
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)
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
SD2520 Databases using XML and JQuery
SDPL 2001Notes 5.1: Additional XPath & XSLT1 5.1 XPath & XSLT: Additional features n XPath support for –arithmetical operations –processing ID/IDREF cross-references.
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.
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.
Navigating XML. Overview  Xpath is a non-xml syntax to be used with XSLT and Xpointer. Its purpose according to the W3.org is  to address parts of an.
SDPL 20075: Overview of XSLT1 5 Document Transformations n XSLT (1.0 W3C Rec. 11/1999; XSLT 2.0 Rec. 1/07) –A language for transforming XML documents –initial.
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.
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
SDPL 2006XSLT: Additional Features and Computing1 5.1 Additional Features n XPath support for –arithmetics –processing ID/IDREF cross-references –manipulation.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
XSLT. XSL comprises of –XSLT: Is a language for transforming XML documents into other XML documents –FO: XML vocabulary for specifying formatting XSL.
Transforming XML Part II XML Document Transformation with XSLT John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
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.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
Processing of structured documents Spring 2003, Part 7 Helena Ahonen-Myka.
XPath. Why XPath? Common syntax, semantics for [XSLT] [XPointer][XSLT] [XPointer] Used to address parts of an XML document Provides basic facilities for.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
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.
More on XSLT 07. More on XSLT © Aptech Limited XPath  In this first lesson, XPath, you will learn to:  Define and describe XPath.  Identify nodes according.
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.
SDPL 2001Notes 5: XSLT1 5. Document Transformations n XSLT (W3C Rec. Nov-99) –A language for transforming XML documents »representative of features common.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
SDPL 20064: Introduction to Style Sheets1 4. Introduction to Style Sheets n Discussed recently: –(APIs for) procedural manipulation of documents n Now.
XPath. XPath, the XML Path Language, is a query language for selecting nodes from an XML document. The XPath language is based on a tree representation.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
SDPL 2007XSLT: Additional Features and Computing1 5.1 Additional Features n XPath for arithmetics, cross-references, and string manipulation n Generating.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
CSE3201/CSE4500 XPath. 2 XPath A locator for items in XML document. XPath expression gives direction of navigation.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
Grouping Robin Burke ECT 360. Outline Grouping: Sibling difference method Uniquifying in XPath Grouping: Muenchian method Generated ids Keys Moded Templates.
1 The XPath Language. 2 XPath Expressions Flexible notation for navigating around trees A basic technology that is widely used uniqueness and scope in.
CITA 330 Section 5 XPath. XSL XSL (Extensible Stylesheet Language) is the standard language for writing stylesheets to transform XML documents among different.
5 Copyright © 2004, Oracle. All rights reserved. Navigating XML Documents by Using XPath.
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.
XML Path Language Andy Clark 17 Apr 2002.
CS 431 – February 28, 2005 Carl Lagoze – Cornell University
Presentation transcript:

SDPL 2002Notes 5.1: Additional XPath & XSLT1 5.1 Additional features of XPath & XSLT n XPath support for –arithmetical operations –processing ID/IDREF cross-references –manipulation of strings n Generating text –for content –for attribute values n Repetition, sorting and conditional processing n Generating numbers

SDPL 2002Notes 5.1: Additional XPath & XSLT2 XPath: Arithmetical Operations Operations for double-precision (64 bit) floating-point numbers +, -, *, div, mod (same as % in Java) Operations for double-precision (64 bit) floating-point numbers +, -, *, div, mod (same as % in Java) –functions to map numbers to integers: »floor(-1.1) = -2, floor(1.1)=floor(1.5)=1 »ceiling(-1.1) = -1, ceiling(1.1)=ceiling(1.5)=2 »round(-1.1) = -1, round(1.1)= 1, round(-1.5) = -1, round(1.5) = 2

SDPL 2002Notes 5.1: Additional XPath & XSLT3 Cross-referencing Function id selects elements by their unique ID Function id selects elements by their unique ID –NB: ID attributes need to be declared (in DTD or its internal subset; See an example later) n Examples: –id('sect:intro') selects the element with unique ID "sect:intro" –id('sect:intro')/para[5] selects the fifth para child of the above element –id('sect1 sect2 sect3') selects 3 sections (if they have the corresponding ID values)

SDPL 2002Notes 5.1: Additional XPath & XSLT4 String manipulation Equality and inequality of strings can be tested with operators = and != Equality and inequality of strings can be tested with operators = and != –"foo" = 'foo' ; "foo" != "Foo" n Concatenation (of two or more strings), –concat("dog", "bert") = "dogbert" Testing for substrings: Testing for substrings: –starts-with("dogbert", "dog") = true() –contains("dogbert", "gbe") = true()

SDPL 2002Notes 5.1: Additional XPath & XSLT5 XPath: more string functions –substring-before("dogbert", "bert") = substring-before("dogbert", "b") = "dog" –substring-after("dogbert", "g")= "bert" –substring( string, startpos, length? ): »substring("dogbert", 1, 3) = "dog" »substring("dogbert", 3) = "gbert" –string-length("dogbert")=7 –translate( Str, ReplacedChars, ReplacingChars ): »translate("dogbert", "dgo", "Dli") = "Dilbert"

SDPL 2002Notes 5.1: Additional XPath & XSLT6 Computing generated text The string-value of an expression can be inserted in the result tree by instruction The string-value of an expression can be inserted in the result tree by instruction –if the expression evaluates to a node-set, the value of the first node in document order is used n Consider transforming source elements like Charlie Parker Charlie Parker to the form Charlie ("Bird") Parker

SDPL 2002Notes 5.1: Additional XPath & XSLT7 Computing generated text (2) This can be specified by template rule This can be specified by template rule (" ") (" ") Verbatim text (like the white space above) can be inserted using xsl:text Verbatim text (like the white space above) can be inserted using xsl:text

SDPL 2002Notes 5.1: Additional XPath & XSLT8 Attribute value templates The string-value of an expression can be inserted in an attribute value by surrounding the expression by braces { and } The string-value of an expression can be inserted in an attribute value by surrounding the expression by braces { and } Consider transforming source element Consider transforming source element<photo> Mary.jpg Mary.jpg into form into form

SDPL 2002Notes 5.1: Additional XPath & XSLT9 Attribute value templates (2) Attribute value templates (2) This can be specified by template rule This can be specified by template rule Expressions {file} and are evaluated in the context of the current node (the photo element) Expressions {file} and are evaluated in the context of the current node (the photo element)

SDPL 2002Notes 5.1: Additional XPath & XSLT10 XSLT: Repetition Nodes can be "pulled" from source for processing using instruction Template Nodes can be "pulled" from source for processing using instruction Template –the template is applied to each of the selected nodes (0, 1 or more), each node in turn as the current node »in document order, unless sorted using xsl:sort instructions (see later)

SDPL 2002Notes 5.1: Additional XPath & XSLT11 Example (of xsl:for-each ) n Consider formatting the below document as HTML: ]> The Joy of XML Getting Started Helen Brown says that processing XML documents is fun. Dave Dobrik agrees. Family affairs Bob Brown is the husband of Helen Brown. Finishing Up As we discussed in, processing XML documents is fun. ]> The Joy of XML Getting Started Helen Brown says that processing XML documents is fun. Dave Dobrik agrees. Family affairs Bob Brown is the husband of Helen Brown. Finishing Up As we discussed in, processing XML documents is fun.

SDPL 2002Notes 5.1: Additional XPath & XSLT12 Example: Table of contents n A table of contents can be formed of section titles: Table of Contents Table of Contents

SDPL 2002Notes 5.1: Additional XPath & XSLT13 Example (cont; Cross references) Cross references (to sections) can also be processed using xsl:for-each: Cross references (to sections) can also be processed using xsl:for-each: Section (...) Section (...) With this rule the source fragment With this rule the source fragment As we discussed in As we discussed in becomes As we discussed in Section (Getting …)

SDPL 2002Notes 5.1: Additional XPath & XSLT14 XSLT Sorting A sorted order for the processing of nodes with xsl:for-each and xls:apply-templates can be specified by A sorted order for the processing of nodes with xsl:for-each and xls:apply-templates can be specified by controlled by attributes of xsl:sort like controlled by attributes of xsl:sort like –select : expression for the sort key –data-type : "text" (default) or "number" – order : "ascending" (default) or "descending" The first xsl:sort specifies the primary sort key, the second one the secondary sort key, and so on. The first xsl:sort specifies the primary sort key, the second one the secondary sort key, and so on.

SDPL 2002Notes 5.1: Additional XPath & XSLT15 Example (cont; Sorted index of names) All names can be collected in a last-name-first-name order using the below template All names can be collected in a last-name-first-name order using the below template Index, Index, n This creates an UL list with items Brown, Bob Brown, Helen Brown, Helen Dobrik, Dave Brown, Bob Brown, Helen Brown, Helen Dobrik, Dave

SDPL 2002Notes 5.1: Additional XPath & XSLT16 What about duplicates? Is it possible to eliminate duplicate values like Brown, Helen Brown, Helen ? Is it possible to eliminate duplicate values like Brown, Helen Brown, Helen ? n Yes (but not that straightforward) n Using conditional instructions –See next

SDPL 2002Notes 5.1: Additional XPath & XSLT17 Conditional processing A template can be instantiated or ignored based on the value of a test Boolean expression, using A template can be instantiated or ignored based on the value of a test Boolean expression, using Template Template Example: a comma-separated list of names: Example: a comma-separated list of names:,,

SDPL 2002Notes 5.1: Additional XPath & XSLT18 Conditional processing (2) n Also a case-like construct: … … … … … </xsl:choose>

SDPL 2002Notes 5.1: Additional XPath & XSLT19 Example (cont; Eliminating duplicate names) No access to other nodes (except current() ) in the list of xsl:for-each (?) No access to other nodes (except current() ) in the list of xsl:for-each (?) –But can refer to other nodes in the source tree –Process just the first one of duplicate name s:,,

SDPL 2002Notes 5.1: Additional XPath & XSLT20 Generating numbers (1/3) Formatted numbers can be inserted in the result tree by element xsl:number Formatted numbers can be inserted in the result tree by element xsl:number –number can be specified by attribute value=" Expr " –otherwise the number generated based on the position of the current node in the source tree Example 1, a numbered list: Example 1, a numbered list:

SDPL 2002Notes 5.1: Additional XPath & XSLT21 Generating numbers (2/3) n Example 2: Hierarchical numbering (1, 1.1, 1.1.1, 1.1.2, …) for titles of chapters, titles of sections of chapters, and titles of subsections of sections

SDPL 2002Notes 5.1: Additional XPath & XSLT22 Generating numbers (3/3) Example 3: Sequential numbering of note s within chapter s: Example 3: Sequential numbering of note s within chapter s: