Applying eXtensible Style Sheets (XSL)

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

1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSLT (eXtensible Stylesheet Language Transformation) 1.
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.
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 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.
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.
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.
XML – Extensible Markup Language XML eXtensible – add to language. Markup – delimit info using tags. Language – a way to express info.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
CSE3201/CSE4500 Information Retrieval Systems
Introduction technology XSL. 04/11/2005 Script of the presentation Introduction the XSL The XSL standard Tools for edition of codes XSL Necessary resources.
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:
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.
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 Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
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)
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Applying eXtensible Style Sheets (XSL) Ellen Pearlman Eileen Mullin Programming.
Accessing Data Using XML CHAPTER NINE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
ITB Web programming for E- Commerce 1 ITB6227 Programming for E-COMMERCE Lecture Presentation of XML 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.
XSLT. XSLT stands for Extensible Stylesheet Language Transformations XSLT is used to transform XML documents into other kinds of documents. XSLT can produce.
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.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
CHAPTER NINE Accessing Data Using XML. McGraw Hill/Irwin ©2002 by The McGraw-Hill Companies, Inc. All rights reserved Introduction The eXtensible.
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:
In this session, you will learn to:
.
XSLT: The XML transformation language
Session II Chapter 14 – XSLT
In this session, you will learn to:
XML Introduction Bill Jerome.
Displaying XML Data with XSLT
Reference: cit /Lectures/xslt.ppt
Using Extension Elements and Extension Functions with XSLT and XPath
XSLT 1.0.
ACG 4401 XSLT Extensible Stylesheet Language for Transformations
Session II Chapter 2 - XSLT
Extensible Markup Language
XML WITH CSS.
WHAT IS XSLT?.
XSL XSLT and XPath 24-Feb-19.
XSL XSLT and XPath.
New Perspectives on XML
eXtensible Markup Language XML
Unit 6 - XML Transformations
Presentation transcript:

Applying eXtensible Style Sheets (XSL) Ellen Pearlman Eileen Mullin Programming the Web Using XML

Learning Objectives Learn how XSL can transform XML documents into other formats such as HTML Examine how an XSL style sheet consists of a set of rules called templates Discover the three components that comprise XSL: XSLT, XPath, and XSL Formatting Objects Use XSLT to output an XML source document into an XML result document. Use XPath expressions in matching patterns to locate parts of an XML document.

CSS and XSL You can use XSL to transform documents – for example, to transform XML data into an HTML document with a CSS stylesheet on a Web server. In this way, XSL and CSS complement each other and can even be used together. You can also use XSL to format data based its value – for example, to display negative numbers in a financial report in red.

Understanding XSL XSL consists of three parts: XSLT, a language for transforming XML documents XPath, a language that defines parts of an XML document XSL Formatting Objects, a vocabulary for styling XML documents

How XSL Works XSL can filter and sort XML data using the criteria you define, as well as format its display based on the value of the data itself. When it’s output, you can use XSL to send your XML data to various devices, including handhelds, print, or voice output.

How XSL Works (2) The XSLT processor reads an XML file and an XSLT stylesheet, then outputs another file based on the instructions found in the stylesheet.

Using XSLT to Transform XML Documents with XSL XSLT is the part of XSL that can turn one XML document into another. XSLT is a template-based programming language. An XSLT template can also introduce new XML elements into the output document it creates, or remove others. XSLT lets different kinds of software applications exchange XML-enabled data with one another.

Using XSLT to Convert an XML Source Tree Into an XML Result Tree

How XSLT Works You need two starting documents for an XSLT transformation – an XML “source” document and an XSLT stylesheet – used to create a single "result" document. The XSLT stylesheet is applied to an XML document’s source tree to generate a result tree that is typically saved as an XML or HTML document. Once a match is found, XSLT transforms the matching part of the source document into the result document.

Learning the Details of XSL Stylesheets Every XSL stylesheet needs to identify the XSL namespace (abbreviated as xslns) so that the parser knows what version of XSLT to use. Accordingly, an XSLT stylesheet statement defines a root element called <xsl:stylesheet> or <xsl:transform>. This might appear as: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> or: <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

Example: gamecatalog.xml <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <game> <title>Escape from Monkey Island</title> <manufacturer>Lucas Arts</manufacturer> <genre>Adventure</genre> <platform>Windows 95/98/ME</platform> <country>USA</country> <cost>9.99</cost> <year>2002</year> </game> . </catalog>

Creating An XSL Stylesheet: gamecatalog.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> <body> <h2>My Game Auctions</h2> <table border="1"> <tr bgcolor="#ffffcc"> <th align="left">Title</th> <th align="left">Manufacturer</th> </tr> <xsl:for-each select="catalog/game"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="manufacturer"/></td> </xsl:for-each> </table> </body> </html> </xsl:template></xsl:stylesheet>

Adding an XSL Stylesheet Reference to the gamecatalog.xml File <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="gamecatalog.xsl"?> <catalog> <game> <title>Escape from Monkey Island</title> <manufacturer>Lucas Arts</manufacturer> <genre>Adventure</genre> <platform>Windows 95/98/ME</platform> <country>USA</country> <cost>9.99</cost> <year>2002</year> </game> . </catalog>

Viewing the gamecatalog.xml File

Filtering You can filter the output from an XML document by setting a criterion for the select attribute in the <xsl:for-each> element. For example, change: <xsl:for-each select="catalog/game"> to: <xsl:for-each select="catalog/game[manufacturer='Activision']]"> then the results listing would show only games that had been released from Activision.

Filtering (2) You can filter your data using several operators, not just the equal (=) sign. These include: * = (equal) *! = (not equal) * < (less than) * > (greater than)

Sorting To sort your output at the same time it’s generated, you add an <xsl:sort> element within the <xsl:for-each> element in your XSL stylesheet: <xsl:for-each select="catalog/game"> <xsl:sort select="manufacturer"/>

Adding Sorting Capabilities to gamecatalog.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> <body> <h2>My Game Auctions</h2> <table border="1"> <tr bgcolor="#ffffcc"> <th align="left">Title</th> <th align="left">Manufacturer</th> </tr> <xsl:for-each select="catalog/game"> <xsl:sort select="title"/> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="manufacturer"/></td> </xsl:for-each> </table> </body> </html> </xsl:template></xsl:stylesheet>

Displaying the gamecatalog.xml File, Sorted by Title

Creating Conditional Statements A conditional statement in an XSL stylesheet. tests your file’s content with a straightforward true-false condition, applying a template only if that specified condition is true. You can use conditional statements to limit the display of data. The format looks like the following: <xsl:if test="cost<'30'"> . </xsl:if>

Adding Conditional Testing to gamecatalog.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> <body> <h2>My Game Auctions</h2> <table border="1"> <tr bgcolor="#ffffcc"> <th align="left">Title</th> <th align="left">Manufacturer</th> </tr> <xsl:for-each select="catalog/game"> <xsl:if test="cost<'30'"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="manufacturer"/></td> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template></xsl:stylesheet>

The Output of the gamecatalog The Output of the gamecatalog.xml file, Showing Games That Cost Less Than $30

Adding a Multiple Conditional Statement to gamecatalog.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> <body> <h2>My Game Auctions</h2> <table border="1"> <tr bgcolor="#ffffcc"> <th align="left">Title</th> <th align="left">Manufacturer</th> </tr> <xsl:for-each select="catalog/game"> <tr> <xsl:choose> <xsl:when test="year>'2002'"> <td><xsl:value-of select="title"/><img src="new.gif"></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="title"/></td> </xsl:otherwise> </xsl:choose> <td><xsl:value-of select="manufacturer"/></td> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>

Applying a Multiple Conditional Statement to Indicate Which Items Are the Most Recent

Applying Templates <?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="essay"> <h2><xsl:apply-templates select="subhead"/></h2> </xsl:template> </xsl:stylesheet>

Debugging XSLT In the same way that a word processor’s spell-checker can ensure there are no obvious misspellings in your writings, validators and debuggers are essential tools for programmers in reducing or eliminating errors in their code. Often debuggers are built into suites of authoring tools, but you shouldn’t need something that complex to check your own errors. For example, Macromedia’s Dreamweaver is a sophisticated suite of tools for Web designers and developers.

Using the XSLT Debugging Feature in Altova’s XMLSpy Program

The Free XSLDebugger Program

The End