1 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Using Extension Elements and Extension Functions with XSLT and XPath Roger L. Costello.

Slides:



Advertisements
Similar presentations
1 Roger L. Costello 16 June 2010 XQuery
Advertisements

1 The MITRE Using XSL to Generate XHTML Documents Roger L. Costello XML Technologies.
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. 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.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSLT (eXtensible Stylesheet Language Transformation) 1.
+ 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)
JAXP Transformation Package and Xalan Extensions 黃立昇
Rendering XML documents with XSL The most powerful approaches to rendering XML documents involve using XSL (eXtensible Stylesheet Language) XSL enables.
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.
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 Copyright (c) [2001]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Enhance HTML Documents Roger L. Costello XML Technologies.
1 Copyright (c) [2000]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents into Text Files Roger L. Costello XML Technologies.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
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.
1 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Using Extension Elements and Extension Functions with XSLT and XPath Roger L. Costello.
SD2520 Databases using XML and JQuery
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.
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 for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
ITR3 lecture 3: Namespaces, XML Schema & XSL Thomas Krichel
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
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:
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
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 part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
Extending XML Schemas XML Schemas: Best Practices A set of guidelines for designing XML Schemas Created by discussions on xml-dev.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
Lecture 11 XSL Transformations (part 1: Introduction)
Yet more on XSLT. Regular expression handling in EXSLT We saw that the EXSLT extensions are divided into a group of modules, each of which has its own.
 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.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
1 Copyright (c) [2000]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents Roger L. Costello XML Technologies.
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.
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.
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.
1 Whitespace Handling Roger L. Costello XML Technologies.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations Presenting XML and XBRL.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
© 2013 The MITRE Corporation. All rights reserved. XSLT Streaming Terminology Understanding “Climbing” Roger L. Costello, February 3, 2014.
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.
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.
Unit 4 Representing Web Data: XML
Using XSLT and XPath to Transform XML Documents
Using Extension Elements and Extension Functions with XSLT and XPath
ACG 4401 XSLT Extensible Stylesheet Language for Transformations
Chapter 7 Representing Web Data: XML
CS 431 – February 28, 2005 Carl Lagoze – Cornell University
Presentation transcript:

1 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Using Extension Elements and Extension Functions with XSLT and XPath Roger L. Costello XML Technologies

2 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Extension Elements The XSL processor understands how to process xsl:template, xsl:apply-templates, xsl:if, xsl:for-each, etc –That is, it understands the vocabulary in the XSL namespace XSL Processor implementers oftentimes provide additional elements that you may use in your stylesheet –These extension elements will belong to a namespace defined by the implementer

3 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Example Extension Element: instruct the xsl processor to output to another file Many of the xsl processor implementers provide an extension element that instructs the xsl processor to output the contents of the element to another file. –Thus, your stylesheet can generate multiple output files! XSL Processor XML XSL

4 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Vendor-specific Each implementor gives the extension element a different name: –saxon calls it: output –xalan calls it: write

5 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. How to use an extension element 1. Declare the namespace that the extension element belongs to: saxon: xmlns:saxon=" xalan: xmlns:xalan=" 2. Indicate that any element that is namespace qualified by the prefix is an extension element, i.e., it has a specific meaning and should be processed using the implementer's code: saxon: extension-element-prefixes="saxon" xalan: extension-element-prefixes="xalan" 3. Use the extension element: saxon: -- anything in here will go to the file specified --- xalan: -- anything in here will go to the file specified ---

6 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Problem Write a stylesheet which outputs the platinum members in one file, the gold members in another file, and the third file is an index to the other two files.

7 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. FitnessCenter.xsl FitnessCenter.xml XSL Processor gold.xml new-FitnessCenter.xml platinum.xml

8 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. This element instructs an xsl processor to copy to the output file the element selected by xpath, plus all its descendents. This instructs the xsl processor to copy everything from to i.e., the Member element and all its descendents.

9 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. <xsl:stylesheet xmlns:xsl=" xmlns:saxon=" extension-element-prefixes="saxon" version="1.0"> See extension-example01

10 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Don’t forget extension-element- prefixes The extension-element-prefixes is used to tell the xsl processor, "whenever you encounter an element with any of these prefixes listed here you are to treat it as an extension element, and process it using the implementer's code" If you fail to do so the xsl processor will simply output the element literally (see extension-example02)

11 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Extension Functions We have seen some of the functions that XSL provides: substring(), contains(), substring-before, etc. Many xsl processor implementers provide additional functions. You signify that a function is an extension function by namespace qualifying it.

12 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Dynamic (run-time) Evaluation Many xsl processor implementers give you an extension function that enables you to dynamically evaluate an expression. –That is, you can generate the expression on the fly, or read it in from an external file. SAXON provides an extension function called evaluate to do this.

13 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. FitnessCenter.xsl FitnessCenter.xml XSL Processor checkFitnessCenter.xml results.xml This file contains expressions that are dynamically evaluated against FitnessCenter.xml Example: provide an xpath expression that ensures that each Member's level attribute is either Platinum or Gold, and nothing else.

14 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. <xsl:stylesheet xmlns:xsl=" xmlns:saxon=" extension-element-prefixes="saxon" version="1.0"> <xsl:variable name="tests" select="document('checkFitnessCenter.xml')"/> SUCCEEDED FAILED Now any references is to elements in checkFitnessCenter.xml Takes us back to referencing elements in FitnessCenter.xml

15 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents that contain Namespaces Roger L. Costello XML Technologies

16 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Problem Suppose that the document that we are processing is using namespaces: Jeff lightgrey Note that we have a default namespace declaration. Thus, FitnessCenter, Member, Name, Phone, and FavoriteColor all belong to the namespace.

17 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. <xsl:stylesheet xmlns:xsl=" version="1.0"> Your name is: (see namespaces-example01) Output: -- empty --

18 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Why is the output empty? Your name is: This template does not match any element in the instance document! This template matches on a Member element in no namespace. However, in our instance document the Member element is in the namespace, i.e., {

19 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Namespace Terminology { Expanded name = The combination of the namespace URI and the local name Local name Namespace URI

20 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Namespace Terminology (cont.) … prefix

21 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. local-name() This is a built-in function which returns a string, corresponding to the local name of the element. Local name = Output: Local name = FitnessCenter Local name = Member Local name = Name Local name = Phone Local name = FavoriteColor (see namespaces-example02)

22 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. <xsl:stylesheet xmlns:xsl=" version="1.0"> Your name is: (see namespaces-example03) Output: Your name is: Jeff

23 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Alternatively <xsl:stylesheet xmlns:xsl=" xmlns:gym=" " version="1.0"> Your name is: Declare the gym namespace Match on the Member element in the gym namespace Select the Name element in the gym namespace (see namespaces-example04)

24 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. namespace-uri() This is a built-in function which returns a string corresponding to the namespace URI of the node. Local name = Namespace URI = Output: Local name = FitnessCenter Namespace URI = Local name = Member Namespace URI = Local name = Name Namespace URI = Local name = Phone Namespace URI = (see namespaces-example05)

25 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. name() Revisited We have seen the name() function before. It returns the name of the node. But what name does it return if the node is in a namespace? –Answer: it returns the element name and its prefix (this is called the QName, for Qualified Name)

26 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Jeff lightgrey Local name = Namespace URI = Name =

27 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Output: Local name = FitnessCenter Namespace URI = Name = gym:FitnessCenter Local name = Member Namespace URI = Name = gym:Member Local name = Name Namespace URI = Name = gym:Name Local name = Phone Namespace URI = Name = gym:Phone Local name = Phone Namespace URI = Name = gym:Phone Local name = FavoriteColor Namespace URI = Name = gym:FavoriteColor (see namespaces-example06)

28 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Identity transform - copying namespace declarations Recall our identity transform stylesheet: Iterate through each attribute and add them as attributes onto the element.

29 Copyright (c) [2002]. Roger L. Costello. All Rights does not select namespace declarations! will only select non-namespace declaration attributes. It will not select namespace declaration attributes <Library xmlns=" xmlns:xsi=" id="Boston Public Library"> This will be selected These will not be selected

30 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Identity transformation for XML documents containing namespaces? So how do we create a stylesheet that can copy over namespace declarations, along with the other attributes? –Answer: use the element

31 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. This element will copy the current element and all namespace declarations to the output file. Shallow copy (copy current node) Cf: –Deep copy (Copy current tree ) –copy all attributes and namespace nodes –copy all descendants

32 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. <xsl:stylesheet xmlns:xsl=" version="1.0"> (see namespaces-example07) The problem with this identity transform stylesheet is that it's not set up to allow us to make changes to elements/attributes.

33 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. <xsl:stylesheet xmlns:xsl=" version="1.0"> Error! Attempting to create an element in a namespace, but the namespace has not been declared yet!

34 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. <xsl:stylesheet xmlns:xsl=" version="1.0"> Simultaneously declare the element and its namespace Simultaneously declare the attribute and its namespace (see namespaces-example08)