XSL XSLT and XPath.

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.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
XSLT 11-Apr-17.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSLT (eXtensible Stylesheet Language Transformation) 1.
XML 6.2 XSL / XSLT 6. What is XSL? XSL stands for eXtensible Stylesheet Language CSS was designed for styling HTML pages, and can be used to style XML.
XSL XSLT and XPath 11-Apr-17.
+ XSL eXtensible Stylesheet Language. + 2 XML Lecture Adapted from the work of Prof Mark Baker ACET, University of Reading.
XML and XSL Transforming your XML documents with eXtensible Stylesheet Language Transformations [Optional Lecture]
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XML Unit 6 October 31. XML, review XML is used to markup data Used to describe information Uses tags like HTML –But all tags are user-defined –Must be.
Extensible Stylesheet Language (XSL) By Example Tony Wat 9 October 2002.
Lecture 10. Back to the table example We can now return to considering in detail the first XSLT style-sheet we saw –The one which, when applied to the.
XSLT eXtensible Stylesheet Language Transformations Naveed Arshad.
Rendering XML documents with XSL The most powerful approaches to rendering XML documents involve using XSL (eXtensible Stylesheet Language) XSL enables.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
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
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
XSL Transformations Transforming XML document into other (XML) documents 1XSL Transformations.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
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.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
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.
WORKING WITH XSLT AND XPATH
Session II Chapter 2 – Chapter 2 – XSLhttp://
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall XML Transformation: XSLT Semantic Web - Spring 2007 Computer.
XHTML,XML M.Abdullah Mrian. What is the XHTML Why XHTML ?
Set 8: XML, XPath, and XSLT (Chapters ,14.8) IT452 Advanced Web and Internet Systems Some XSLT examples derived from prior textbook: “Professional.
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 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)
 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.
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.
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
1 XMLXSL(T) and CSS NOEA/PQC (rev. fen) 2007 Stylesheets CSS:Cascading Style Sheets XSL(T):eXtended Stylesheet Language (Transformations)
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall XML Transformation: XSLT Semantic Web - Fall 2005 Computer.
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.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
April 20023CSG1XSL 1 Electronic Commerce XSL transformations John Wordsworth Department of Computer Science The University of Reading
Session IV Chapter 14 – Chapter 14 – XSLThttp://
In this session, you will learn to:
XSLT: The XML transformation language
XML Introduction Bill Jerome.
Displaying XML Data with XSLT
Reference: cit /Lectures/xslt.ppt
eXtensible Stylesheet Language
XSLT 1.0.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Session II Chapter 2 - XSLT
XML Data Introduction, Well-formed XML.
Applying eXtensible Style Sheets (XSL)
XML WITH CSS.
Introduction to Web Science
WHAT IS XSLT?.
XSL XSLT and XPath 24-Feb-19.
Attributes, Empty-Element Tags, and XSL
7 September 1999 The Basics of XSLT Assuming a basic knowledge of XML and XML Namespaces Thomas G. Habing Grainger Engineering Library Information Center.
Unit 6 - XML Transformations
Presentation transcript:

XSL XSLT and XPath

What is XSL? XSL stands for Extensible Stylesheet Language CSS was designed for styling HTML pages, and can be used to style XML pages XSL was designed specifically to style XML pages, and is much more sophisticated than CSS XSL consists of three languages: XSLT (XSL Transformations) is a language used to transform XML documents into other kinds of documents (most commonly HTML, so they can be displayed) XPath is a language to select parts of an XML document to transform with XSLT XSL-FO (XSL Formatting Objects) is a replacement for CSS There are no current implementations of XSL-FO, and we won’t cover it

How does it work? The XML source document is parsed into an XML source tree You use XPath to define templates that match parts of the source tree You use XSLT to transform the matched part and put the transformed information into the result tree The result tree is output as a result document Parts of the source document that are not matched by a template are typically copied unchanged

Simple XPath Here’s a simple XML document: <?xml version="1.0"?> <library> <book> <title>XML</title> <author>Gregory Brill</author> </book> <book> <title>Java and XML</title> <author>Brett McLaughlin</author> </book> </library > XPath expressions look a lot like paths in a computer file system / means the document itself (but no specific elements) /library selects the root element /library/book selects every book element //author selects every author element, wherever it occurs

Simple XSLT <xsl:for-each select="//book"> loops through every book element, everywhere in the document <xsl:value-of select="title"/> chooses the content of the title element at the current location <xsl:for-each select="//book"> <xsl:value-of select="title"/> </xsl:for-each> chooses the content of the title element for each book in the XML document

Using XSL to create HTML Our goal is to turn this: <?xml version="1.0"?> <library> <book> <title>XML</title> <author>Gregory Brill</author> </book> <book> <title>Java and XML</title> <author>Brett McLaughlin</author> </book> </library > Into HTML that displays something like this: Book Titles: • XML • Java and XML Book Authors: • Gregory Brill • Brett McLaughlin

What we need to do We need to save our XML into a file (let’s call it books.xml) We need to create a file (say, books.xsl) that describes how to select elements from books.xml and embed them into an HTML page We do this by intermixing the HTML and the XSL in the books.xsl file We need to add a line to our books.xml file to tell it to refer to books.xsl for formatting information

books.xml, revised <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="book-titles.xsl"?> <library> <book> <title>XML</title> <author>Gregory Brill</author> </book> <book> <title>Java and XML</title> <author>Brett McLaughlin</author> </book> </library >

Desired HTML <html> <head> <title>Book Titles and Authors</title> </head> <body> <h2>Book titles:</h2> <ul> <li>XML</li> <li>Java and XML</li> </ul> <h2>Book authors:</h2> <ul> <li>Gregory Brill</li> <li>Brett McLaughlin</li> </ul> </body> </html>

XSL outline <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> ... </html> </xsl:template> </xsl:stylesheet>

Selecting titles and authors <h2>Book titles:</h2> <ul> <xsl:for-each select="//book"> <li> <xsl:value-of select="title"/> </li> </xsl:for-each> </ul> <h2>Book authors:</h2> ...same thing, replacing title with author Notice that XSL can rearrange the data; the HTML result can present information in a different order than the XML

All of book.xsl <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/ XSL/Transform"> <xsl:template match="/"> <html> <head> <title>Book Titles and Authors</title> </head> <body> <h2>Book titles:</h2> <ul> <xsl:for-each select="//book"> <li> <xsl:value-of select="title"/> </li> </xsl:for-each> </ul> <h2>Book authors:</h2> <ul> <xsl:for-each select="//book"> <li> <xsl:value-of select="author"/> </li> </xsl:for-each> </ul> </body> </html> </xsl:template> </xsl:stylesheet>

How to use it In a modern browser, such as Netscape 6, Internet Explorer 6, or Mozilla 1.0, you can just open the XML file Older browsers will ignore the XSL and just show you the XML contents as continuous text You can use a program such as Xalan, MSXML, or Saxon to create the HTML as a file This can be done on the server side, so that all the client side browser sees is plain HTML The server can create the HTML dynamically from the information currently in XML

The End