Digital Media Technology

Slides:



Advertisements
Similar presentations
XSLT (eXtensible Stylesheet Language Transformation) 1.
Advertisements

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.
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.
XSL Unit 6 November 2. XSL –eXtensible Stylesheet Language –Basically a stylesheet for XML documents XSL has three parts: –XSLT –XPath –XSL-FO.
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.
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.
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.
DMT Seminar XSLT 2 Fleur Praal & Jeroen van Honk – 28 October 2014 Leiden University. The university to discover.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
CSE3201/CSE4500 Information Retrieval Systems
CIS 451: XSL Dr. Ralph Westfall February, Problems With XML no formatting capabilities contra formatting tags like, etc. in HTML CSS can be used.
WORKING WITH XSLT AND XPATH
Transforming XML Part II XML Document Transformation with XSLT John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
Digital Media Technology Week 6. XML Source XSLT Stylesheet XML Result 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 "
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.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
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.
Digital Media Technology Week 5: XML and Presentation Peter Verhaar.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Applying eXtensible Style Sheets (XSL) Ellen Pearlman Eileen Mullin Programming.
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.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
Digital Media Technology Week 7: XSLT 3. Characteristics of digital models □ “a set of ontological commitments” □ Expressed in a “formal language”
Digital Media Technology Week 6: Introduction to XSLT Peter Verhaar.
XML Schema – XSLT Week 8 Web site:
In this session, you will learn to:
XSLT: The XML transformation language
Query Languages for XML
Session II Chapter 14 – XSLT
XSL Transformations (XSLT)
XML Introduction Bill Jerome.
Lecture 21.
Beginning XML 4th Edition.
Seminar on Service Oriented Architecture
Displaying XML Data with XSLT
Digital Media Technology
Reference: cit /Lectures/xslt.ppt
Using XSLT and XPath to Transform XML Documents
Using Extension Elements and Extension Functions with XSLT and XPath
XSLT Part 2.
eXtensible Stylesheet Language
XSLT 1.0.
Extensible Markup Language XML
ACG 4401 XSLT Extensible Stylesheet Language for Transformations
XSLT Instructors: Geoffrey Fox and Bryan Carpenter
Session II Chapter 2 - XSLT
Introduction to XSLT.
Many-to-many relationship
XPATH & XSLT Đặng Bác Văn Ngô Bá Nam Phương Công nghệ XML và Ứng dụng:
Applying eXtensible Style Sheets (XSL)
XML WITH CSS.
Introduction to Web Science
CS 431 – February 28, 2005 Carl Lagoze – Cornell University
WHAT IS XSLT?.
XSL XSLT and XPath 24-Feb-19.
XML: eXtensible Markup Language
Attributes, Empty-Element Tags, and XSL
XSL XSLT and XPath.
More XML XML schema, XPATH, XSLT
New Perspectives on XML
7 September 1999 The Basics of XSLT Assuming a basic knowledge of XML and XML Namespaces Thomas G. Habing Grainger Engineering Library Information Center.
Presentation transcript:

Digital Media Technology Week 6: Introduction to XSLT Peter Verhaar

Example: XML source <?xml version="1.0" encoding="UTF-8"?> <letter> <head>Letter from De Erven F. Bohn to W. Blackwood and sons, January 22nd, 1873</head> <body> <dateline> <place>Haarlem</place> <date>22 January 1873</date> </dateline> <greeting>Dear Sirs!</greeting> <p>We beg to apply to you the kind request for sending us one week before the publication one copy of Bulwer&apos;s novel: <title>Kenelm Chillingly, His adventures and opinions</title>, which book you have in the press, for what we are inclined to pay 30 £. When it were possible to send us already now the first volume by the post; it would be yet more agreeable. Mr H.A. Kramers at Rotterdam readily will be our pledge.</p> <salute> your truly</salute> <signed>De Erven F. Bohn</signed> </body> </letter>

Getting started Include a template that points to the root element of the XML source. <?xml version="1.0" encoding="UTF-8"?> <letter> <head>Letter from De Erven F. Bohn to W. Blackwood and sons, January 22nd, 1873</head> <body> …. </body> </letter>

XML Result XSLT XML Source <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/ Transform" version="1.0"> <xsl:template match="letter"> </xsl:template> </xsl:stylesheet> <?xml version="1.0" encoding="UTF-8"?> <letter> … </letter> XML Result

Elements within <xsl:template> Literal text can be added with the <xsl:text>element. e.g. <xsl:text>This sentence will be visible in the result.</xsl:text> HTML tags may be added directly e.g. <i><xsl:text>This text will be italicised<xsl:text></i>

Elements within <xsl:template> Use <xsl:value-of> to select text from the XML source. e.g. <xsl:value-of select=“head”/> <xsl:value-of select=“body/dateline”/> Note that the paths in the select-attribute must depart from the element mentioned in the match-attribute of <xsl:template>

XSLT stylesheet <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match=“letter"> <html> <head> <title> <xsl:text>XSLT transformation</xsl:text> </title> </head> <body> <h2> <xsl:value-of select=“head”> </h2> </body> </html> </xsl:template> </xsl:stylesheet>

Exercise 1

Example: XML source <?xml version="1.0" encoding="UTF-8"?> <EU> <country> <name> Belgium </name> <capital>Brussels</capital> </country> <name>Cyprus </name> <capital>Nicosia</capital> <name>Denmark </name> <capital>Copenhagen</capital> … </EU>

XSLT stylesheet <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="EU"> <ul><li> <xsl:text>The capital of </xsl:text> <xsl:value-of select="country/name"/> <xsl:text> is </xsl:text> <xsl:value-of select="country/capital"/> <xsl:text>.</xsl:text> </li></ul> </xsl:template> </xsl:stylesheet>

<xsl:for-each> needs to be used if all the elements on a certain level need to be shown. This XSLT element takes a select-attribute Note that the paths within <xsl:for-each> must depart from the element that is mentioned mentioned in the select-attribute.

XSLT stylesheet <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="EU"> <ul> <xsl:for-each select="country"> <li> <xsl:text>The capital of </xsl:text> <xsl:value-of select="name"/> <xsl:text> is </xsl:text> <xsl:value-of select="capital"/> <xsl:text>.</xsl:text> </li> </xsl:for-each> </ul> </xsl:template> </xsl:stylesheet>

Exercise 2

<xsl:sort> Use <xsl:sort> to sort a list alphabeticaly or numerically This XSLT element also takes a select-attribute. It refers to the element the XSLT processor must sort by <xsl:sort> must be the direct child of <xsl:for-each> (or <xsl:apply-templates>)

Exercise 3

<xsl:if> <xsl:if> takes a “test” attribute The instructions within <xsl:if> will only be carried out if the criterion in the test attribute can be evaluated as true Example: <xsl:if test=“date”> <xsl:value=“date”/> </xsl:if>

Exercise 4

Operators that can be used to formulate such tests: The items that will be selected within the <xsl:for-each> loop can be filtered by adding a criterion within square brackets, directly after the element name. Operators that can be used to formulate such tests: = Equal to != Not equal to < Less than > Greater than

Exercise 5

Elements within <xsl:template> <xsl:value-of> <xsl:text> <xsl:for-each> <xsl:sort> <xsl:if>