 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 – XSL: Extensible Stylesheet Language Transformations (XSLT) Outline 12.1Introduction 12.2Setup.

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 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.
XSLT 11-Apr-17.
 2001 Prentice Hall, Inc. All rights reserved. 1.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
SPECIAL TOPIC XML. Introducing XML XML (eXtensible Markup Language) ◦A language used to create structured documents XML vs HTML ◦XML is designed to transport.
XSL XSLT and XPath 11-Apr-17.
Introduction to XSLT. What is XML? Design Goals of XML XML Format XML Declaration ElementsAttributes.
+ 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)
XSL Transformations (XSLT) Meghasyam Bokam April’1 st, 2002.
1 Final Project Pre-presentation: 10 minutes WeekDateGroup No 135/13(3)14, 9, 8 145/20(3)4, 1, 7 155/27 (6)3, 11, 13, 2, 12, 5 166/03(3)10, 6, 15 6/3 Class.
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.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 11 – XML Path Language (XPath) Outline 11.1Introduction 11.2Nodes 11.3Location Paths Axes.
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.
SD2520 Databases using XML and JQuery
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.
XSLT 1. C ONTENTS XSLT and uses XSLT example Simple XML How XSLT works? Template-match Value-of For-each and sort If Choose-when Apply-templates Where.
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
CSE3201/CSE4500 Information Retrieval Systems
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
CIS 451: XSL Dr. Ralph Westfall February, Problems With XML no formatting capabilities contra formatting tags like, etc. in HTML CSS can be used.
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.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message.
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.
IST 221 Internet Concepts and Applications Introduction to XML II CSS and XSLT Style Sheets.
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)
 2001 Prentice Hall, Inc. All rights reserved. Chapter 15 – Case Study: Message Forum with Active Server Pages Outline 15.1Introduction 15.2Setup and.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 24 – Case Study: ASP.NET and XML Outline 24.1 Introduction 24.2 Setup and Message Forum 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.
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 Copyright (c) [2000]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents Roger L. Costello XML Technologies.
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.
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.
CSE3201/CSE4500 Information Retrieval Systems XSLT – Part 2.
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
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.
XSLT I Robin Burke ECT 360. Outline History / Terminology XSLT processing XSLT syntax XPath XSLT basics Lab.
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.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
Presentation transcript:

 2002 Prentice Hall, Inc. All rights reserved. 1 Chapter 12 – XSL: Extensible Stylesheet Language Transformations (XSLT) Outline 12.1Introduction 12.2Setup 12.3Templates 12.4Creating Elements and Attributes 12.5Iteration and Sorting 12.6Conditional Processing 12.7Copying Nodes 12.8Combining Stylesheets 12.9Variables 12.10Case Study: XSLT and XPath

 2002 Prentice Hall, Inc. All rights reserved Introduction Extensible Stylesheet Language (XSL) –Used to format XML documents –Consist of two parts XSL Transformation Language (XSLT) –Transform XML document from one form to another –Use XPath to match nodes XSL formatting objects –Alternative to CSS

 2002 Prentice Hall, Inc. All rights reserved Setup XSLT processor –Microsoft Internet Explorer 5 –Apache’s Xalan –Java 2 Standard Edition required Download at Installation instructions – –Xalan required Download at xml.apache.org/xalan

 2002 Prentice Hall, Inc. All rights reserved Templates XSLT document –XML document with root element stylesheet –template element Matches specific XML document nodes Uses XPath expression in attribute match

 2002 Prentice Hall, Inc. All rights reserved Templates (cont.) XSLT –Two trees of nodes Source tree corresponds to original XML document Result tree contains nodes produced by transformation –Fig transforms intro.xml into HTML document

 2002 Prentice Hall, Inc. All rights reserved. Outline 6 Fig. 12.1Simple Template. Root element stylesheet XSLT namespace Use XPath expression in template element to match any myMessage element nodes template element contents are placing in resulting tree when myMessage element node is matched <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " Root element stylesheet XSLT namespace template element contents are placing in resulting tree when myMessage element node is matched Use XPath expression in template element to match any myMessage element nodes

 2002 Prentice Hall, Inc. All rights reserved. Outline 7 Fig. 12.2Input XML document. Element stylesheet attaches style sheet to XML document Welcome to XSLT! 10 Element stylesheet attaches style sheet to XML document

 2002 Prentice Hall, Inc. All rights reserved. Outline 8 Fig. 12.3Internet Explorer 5 displaying the results of an XSL transformation. 1 Welcome to XSLT!

 2002 Prentice Hall, Inc. All rights reserved Creating Elements and Attributes Creation of elements and attributes

 2002 Prentice Hall, Inc. All rights reserved. Outline 10 Fig. 12.4XML document containing a list of sports More popular among commonwealth nations More popular in America Most popular sport in the world

 2002 Prentice Hall, Inc. All rights reserved. Outline 11 Fig. 12.5Using XSLT to create elements and attributes. Use attribute match to select XML document root Element apply- templates applies XSLT document templates to specific nodes match element sports and apply templates to sport node’s child nodes Create element title Create attribute id for element title Create comment with element para comments <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " Use attribute match to select XML document root Element apply-templates applies XSLT document templates to specific nodes match element sports and apply templates to sport node’s child nodes Create element title Create attribute id for element title Create comment with element para comments

 2002 Prentice Hall, Inc. All rights reserved. 12 Fig Default XSLT Templates

 2002 Prentice Hall, Inc. All rights reserved. Outline 13 Fig. 12.7Output of transformation More popular among commonwealth nations More popular in America Most popular sport in the world

 2002 Prentice Hall, Inc. All rights reserved Iteration and Sorting XSLT allows –Iteration through node set Element for-each –Sorting node set Element sort –Attribute ascending (i.e., A-Z) –Attribute descending (i.e., Z-A)

 2002 Prentice Hall, Inc. All rights reserved. Outline 15 Fig. 12.8Book table of contents as XML Deitel&apos;s XML Primer Paul 13 Deitel Welcome 18 Easy XML 19 XML Elements? 20 Entities

 2002 Prentice Hall, Inc. All rights reserved. Outline 16 Fig. 12.9Transforming XML data into HTML. Element for-each applies element contents to each preface element node Use element sort to sort nodes (selected by for- each ) in ascending order <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " ISBN by, Element for-each applies element contents to each preface element node Use element sort to sort nodes (selected by for- each ) in ascending order

 2002 Prentice Hall, Inc. All rights reserved. Outline 17 Fig Transforming XML data into HTML (Part 2). Iterate and sort chapter elements Iterate and sort appendix elements Preface ( 37 pages ) Chapter ( 51 pages ) Appendix 61 Iterate and sort chapter elementsIterate and sort appendix elements

 2002 Prentice Hall, Inc. All rights reserved. Outline 18 Fig Transforming XML data into HTML (Part 3) ( 65 pages )

 2002 Prentice Hall, Inc. All rights reserved. Outline 19 Fig Output of the transformation ISBN X - Deitel's XML Primer Deitel's XML Primer 8 by Deitel, Paul Preface 1 13 Welcome ( 2 pages ) Chapter 1 18 Easy XML ( 4 pages ) Chapter 2 23 XML Elements? ( 2 pages ) Appendix 1 28 Entities ( 9 pages )

 2002 Prentice Hall, Inc. All rights reserved. 20 Output from Fig

 2002 Prentice Hall, Inc. All rights reserved Conditional Processing Perform conditional processing –Such as if statement –Use element choose Allows alternate conditional statements Similar to switch statement Has child elements when and otherwise –when element content used if condition is met –otherwise element content used if no conditions in when condition are met

 2002 Prentice Hall, Inc. All rights reserved. Outline 22 Fig Using conditional elements <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " Appointments Year: <xsl:sort select = order = "ascending" 27 data-type = "number"/>

 2002 Prentice Hall, Inc. All rights reserved. Outline 23 Fig Using conditional elements (Part 2). Allow conditional statements Content of when element used if condition is met Content of otherwise element used if no conditions are met Day: 30 / <xsl:when test = 37 > '0500' < '1200'"> 38 Morning ( ): <xsl:when test = 42 > '1200' < '1700'"> 43 Afternoon ( ): <xsl:when test = 47 > '1200' < '1700'"> 48 Evening ( ): <xsl:when test = 52 > '1200' < '1700'"> 53 Night ( ): Entire day: 58 Allow conditional statements Content of when element used if condition is met Content of otherwise element used if no conditions are met

 2002 Prentice Hall, Inc. All rights reserved. Outline 24 Fig Using conditional elements (Part 3) n/a

 2002 Prentice Hall, Inc. All rights reserved. 25 Output from Fig

 2002 Prentice Hall, Inc. All rights reserved Copying Nodes Duplicate nodes from sources tree to result tree –Element copy Produce copy of context node Place copy in result tree No child nodes or attributes are duplicated –Element copy-of Performs copy of subtree Duplicates children (i.e., text, processing instructions, etc.)

 2002 Prentice Hall, Inc. All rights reserved. Outline 27 Fig Using the XSLT element copy. Apply templates to element’s child nodes Replace element content with text <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " How about &apos;Hi World&apos; for a change! Replace element content with text Apply templates to element’s child nodes

 2002 Prentice Hall, Inc. All rights reserved. Outline 28 Fig Resulting transformation How about 'Hi World' for a change! 5 6

 2002 Prentice Hall, Inc. All rights reserved. Outline 29 Fig xsl:copy- of element. Create comment in resulting XML document Duplicate nodes selected by attribute select into resulting XML document <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " The following XML tree has been copied into output Create comment in resulting XML document Duplicate nodes selected by attribute select into resulting XML document

 2002 Prentice Hall, Inc. All rights reserved. Outline 30 Fig Output of the copy-of transformation Welcome to XSLT! 5

 2002 Prentice Hall, Inc. All rights reserved Combining Stylesheets XSLT document can import others –Element import local templates have higher precedence as included templates –Element include Included templates have same precedence as local templates

 2002 Prentice Hall, Inc. All rights reserved. Outline 32 Fig XSLT document being imported <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " Author: 27, 28 29

 2002 Prentice Hall, Inc. All rights reserved. Outline 33 Fig XSLT document being imported (Part 2). Template to match any text and leftover element nodes Template to match any text and leftover element nodes

 2002 Prentice Hall, Inc. All rights reserved. Outline 34 Fig Importing another XSLT document. Use templates in usage2.xsl Template for element title used instead of one defined in usage2.xsl <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " <!-- This template has higher precedence over the 12 templates being imported --> Use templates in usage2.xsl Template for element title used instead of one defined in usage2.xsl

 2002 Prentice Hall, Inc. All rights reserved. Outline 35 Fig Resulting HTML document using XSLT import Deitel's XML Primer Author: Deitel, Paul 7 8 9

 2002 Prentice Hall, Inc. All rights reserved. Outline 36 Fig Combining stylesheets using xsl:include. Include author.xsl and chapters.xsl, but templates in stylesheets have same precedence as local templates <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " Include author.xsl and chapters.xsl, but templates in stylesheets have same precedence as local templates

 2002 Prentice Hall, Inc. All rights reserved. Outline 37 Fig XSLT document for rendering the author’s name <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " Author: 12,

 2002 Prentice Hall, Inc. All rights reserved. Outline 38 Fig XSLT document for rendering chapter names <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " Chapters:

 2002 Prentice Hall, Inc. All rights reserved. Outline 39 Fig Output of an XSLT document using element include. Output from Fig Deitel’s XML Primer 4 Author: 5 Deitel, Paul 6 7 Chapters: 8 9 Easy XML 10 XML Elements?

 2002 Prentice Hall, Inc. All rights reserved Variables Variables for processing information –Element variable

 2002 Prentice Hall, Inc. All rights reserved. Outline 41 Fig Example for xsl:variable. Create element variable with attribute name to store number of pages in book Element value-of uses dollar sign ( $ ) to reference and output variable sum <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " Number of pages = 13 <xsl:variable name = "sum" 14 select = Create element variable with attribute name to store number of pages in book Element value-of uses dollar sign ( $ ) to reference and output variable sum

 2002 Prentice Hall, Inc. All rights reserved. Outline 42 Fig Output of transformation. 1 2 Number of pages = 17

 2002 Prentice Hall, Inc. All rights reserved Case Study: XSLT and XPath XPath Expression –locates elements, attributes and text in XML document –Consider more substantial example Mark up information about Deitel complete training course

 2002 Prentice Hall, Inc. All rights reserved. Outline 44 Fig XML document containing information about complete training courses and Web- based training. Root element product contains complete- TrainingCourses Each complete- TrainingCourse element contains title, book and cd The Complete C++ Training Course: Third Edition C++ How to Program: Third Edition C++ Multimedia Cyber Classroom: Third Edition The Complete Java 2 Training Course: Third Edition Root element product contains completeTrainingCourses Each completeTrainingCourse element contains title, book and cd

 2002 Prentice Hall, Inc. All rights reserved. Outline 45 Fig XML document containing information about complete training courses and Web- based training (Part 2). Root element product also contains books Java How to Program: Third Edition Java Multimedia Cyber Classroom: Third Edition The Complete XML Training Course 43 XML How to Program 44 XML Multimedia Cyber Classroom Getting Started with Microsoft Visual C with an Introduction to MFC C How to Program Root element product also contains books

 2002 Prentice Hall, Inc. All rights reserved. Outline 46 Fig XML document containing information about complete training courses and Web- based training (Part 3). Root element product also contains webBased- Training Introduction to Java programming 61 Advanced C++ programming 62 Programming COM+ with Visual Basic Root element product also contains webBasedTraining

 2002 Prentice Hall, Inc. All rights reserved. Outline 47 Fig XSL stylesheet for transforming axes.xml into HTML. Select all product children of root node Select node descendents of completeTraining- Courses elements <xsl:stylesheet version = "1.0" 7 xmlns:xsl = " Axes example node { font-family: monospace; 18 font-weight: bold; } Decendents of completeTrainingCourse are: <xsl:apply-templates select = 28 "completeTrainingCourses//node()"/> Select all product children of root node Select node descendents of completeTrainingCourses elements

 2002 Prentice Hall, Inc. All rights reserved. Outline 48 Fig XSL stylesheet for transforming axes.xml into HTML (Part 2). Apply templates to add string-values for webBasedTraining nodes to HTML document 31 Self for 32 webBasedTraining is <xsl:apply-templates 35 select = "webBasedTraining"/> Parent of 39 C How to Program is <xsl:value-of select = 44 "name(//parent::node()[. = 'C How to Program'])"/> Child of 50 title 51 element for the second completeTrainingCourse is <xsl:value-of select = 57 "//child::completeTrainingCourse[ 2 ]/title"/> Apply templates to add string- values for webBasedTraining nodes to HTML document

 2002 Prentice Hall, Inc. All rights reserved. Outline 49 Fig XSL stylesheet for transforming axes.xml into HTML (Part 3) Is product the ancestor of 65 XML How to Program ? <xsl:if test = "name(//node()[. = 68 'XML How to Program']/ancestor::product) = 'product'"> 69 Yes First subject preceding Programming COM+ with Visual Basic 78 is <xsl:value-of select = 82 "//subject[. = 'Programming COM+ with Visual Basic' 83 ]/preceding-sibling::subject[ 1 ]"/> First subject following 89

 2002 Prentice Hall, Inc. All rights reserved. Outline 50 Fig XSL stylesheet for transforming axes.xml into HTML (Part 4). Retrieve string-values for title, book and cd elements and add them to HTML document Add string-values for subject element to HTML document Introduction to Java programming 92 is <xsl:value-of select = 96 "//subject[. = 'Introduction to Java programming' 97 ]/following-sibling::subject[ 1 ]"/> Retrieve string-values for title, book and cd elements and add them to HTML document Add string-values for subject element to HTML document

 2002 Prentice Hall, Inc. All rights reserved. 51 Fig HTML page generated by transforming axes.xml with axes.xsl