XML and XSL Transforming your XML documents with eXtensible Stylesheet Language Transformations [Optional Lecture]

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

XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : XSLT.
XSLT 11-Apr-17.
 2001 Prentice Hall, Inc. All rights reserved. 1.
XSL eXtensible Stylesheet Language. What is XSL? XSL is a language that allows one to describe a browser how to process an XML file. XSL can convert an.
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.
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.
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.
XML Extensible Markup Language Standard supported by W3C (World Wide Web Consortium) HTML – End user oriented (presentation) XML – Application oriented.
XML Study-Session: Part IV Transforming XML Documents Copyright Quddus Chong 2001.
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.
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.
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)
Technical Track Session XML Techie Tools Tim Bornholt.
Using XSLT and XPath to Enhance HTML Documents Reference: Roger L. Costello
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.
Chapter 12 Creating and Using XML Documents HTML5 AND CSS Seventh Edition.
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
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.
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,
Implementing Forms and Form Renderers in the Open Source Portfolio David McPherson, Chris Maurer Will Trillich, Janice Smith Materials by Sean Keesler.
Lecture 14 Extensible Stylesheet Language Transformations : XSLT.
 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.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
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.
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)
XSLT Introduction. XSLT is the transformation part of XSL An XSLT file contains rules which are applied against and XML file to produce an output Outputs.
 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.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
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.
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.
Lecture 15 Extensible Stylesheet Language Transformations : XSLT.
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:
Displaying XML Data with XSLT
Unit 6 - XML Transformations
Presentation transcript:

XML and XSL Transforming your XML documents with eXtensible Stylesheet Language Transformations [Optional Lecture]

XSL - Overview XSL is the eXtensible Stylesheet Language XSL is an XML-based language, like WML; but where WML is a content format, XSL is a way to to format content. The process of applying XSL to an XML document is called transforming the document. You transform it from one language--XML--to another: HTML, or maybe WML, or text or who- knows-what; even to another XML language. XSL is to XML as style sheets are to HTML; but XSL is actually much more powerful.

XSL - Overview Where’s the action?  XSL is a client-side technology. Unlike ASP or JSP, it does all its work on the client’s PC.  This means that speed of prsentation of your data depends on the client’s speed. Most web pages don’t work that way!  Since XSL transformations (“XSLT”) are run by the client, your client needs to be capable of XSL. Not all clients are XSL-capable! –Internet Explorer 5.* or less are not XSL-capable. –Internet Explorer 6.0 or higher are XSL-capable. –Netscape 6 is mostly XSL-capable. –Your mobile phone is almost certainly not XSL-capable. Microsoft’s XML parser is named MSXML. MSXML 3.0 is MS’s first XSL-capable parser. 3.0 first shipped with Windows XP.

XSL - Overview What’s it look like?  Remember XML? This is a class about XML.  Sample XML: Hello, world!  And how it looks in IE 6:

XSL - Overview We’re going to use XSL to give visual meaning to those two new tags, document and underlined. HTML defines a set of tags that specify formatting rules;,, and the like all specify visual formatting rules. XSL allows us to define our own tags; just as means underline in HTML, we can make an tag of our own that will underline the XML content. An XSL document defines a list of matchings from a tag and its content to a template expansion of HTML (or other) text.

XSL - Example One Here’s a sample of XSL: <xsl:stylesheet version="1.0” xmlns:xsl="

XSL - Example One...and here’s the result of applying it to the XML:

XSL - Example One So how’d that work? After I created the.xsl file, I added one line to the.xml file: When Internet Explorer loaded the XML file, it found this XSL directive and loaded the XSL file to find the formatting transformation. Then it applied the XSL rules to the XML data, and transformed the XML into HTML.

XSL - Templates and Nodes Remember, XML documents are trees : The current node :  The XSL processor walks the XML document tree, replacing each node with its matching transformation. As it goes, it keeps track of the current node. In your XSL code you can reference the attributes, value, and children of the current node. Root node Child node

XSL - Templates and Nodes A closer look at the XSL code:  The standard XML header is followed by the stylesheet tag:...  The stylesheet lays out a series of template tags:  Within each template, the XSL specifies the rules of replacement. For example, replaces all instances of the “underlined” tag with a bit of HTML formatting--the tags--wrapped around the content.

XSL - Templates and Nodes The XSL template tags  As each node of the source XML is processed, its tag is matched against the list of ’s in the XSL. The XSL processor searches for a tage whose match field matches the XML tag name. If it finds one, it replaces the XML tag with the content specified in the body of the tag.  match=“/” will match the root node of the document.  The tag is XSL for “recurse within this tag”. When the XSL processor encounters this, it calls itself on the content within the current node.

XSL - Example Two A slightly more complex example: John Smith MSc which would render as if it weren’t for the XSL directive...

XSL - Example Two The XSL code: <xsl:stylesheet version="1.0” xmlns:xsl=" Degree sought :

XSL - Example Two And the resulting transformed document:

XSL - Node values and attributes The tag is used to extract values from fields in the XML data.  The value of the select attribute contains an XPath expression. XPath is a language--a part of XSL--that identifies nodes in the source XML so that you can refer to them in your XSL content. Some XPath examples:  select=“/document/frednode” would select a tag that was the immediate child of a tag in the root of the XML tree.  select=“/document//frednode” would select a tag that was a child, directly or indirectly, of a root tag.

XSL - Node values and attributes For example, if we add 28 July 1973 to the end of the content and Birth date :, to the XSL, we get Birth date : July28, 1973 at the end of the output.

XSL - Node values and attributes Perhaps more interesting, the tag has a select=“...” attribute too.  By specifying what to apply the template recursion to, we can actually change the structure of the document: Here instead of mindlessly displaying the content inside the tag in the order it’s entered, we’re displaying it in the order specified. We’re changing the actual tree structure of the XML document as we transform it.

XSL - Example Three You can also use the select syntax to embed the XSL transformation of one node inside that of another: Now the tag will be transformed to include a bulletted printout of the tag.  This works even though the tag isn’t a child of the tag in our original content!

XSL - Loops XSL supports looping over all the similiar child nodes of a tag with the element.  This is handy for laying out tables or lists. For example, you can open your tag and then fill in all the rows.  The select attribute of the for-each tag acts as a search. You can specify the nodes you want to enumerate over, and they’ll be processed in the order in which they appear. You specify the nodes with an XPath path.  Again, this can change the fundamental structure of the document.

XSL - Example Four For example, this code will create a table of all the tags: <table border="1" cellpadding="1" cellspacing="1"> <xsl:apply-templates select="name" /> <xsl:apply-templates select="degree" />

XSL - XPath paths XPath is a complex and powerful way to identify the nodes in an XML document. The path you give is relative to the current node; the path structure is rather like a directory path.  select=“*” : All the immediate children of the current node  select=“bob” : All the immediate children of the current node that are tags  select=“fred/bob” : All the tags which are immediate children of the tags immediately beneath the current node  select=“fred//bob” : All the tags which are descendants--at any depth--of the tags immediately beneath the current node  select=“.//bob” : All the tags anywhere beneath the current node  select=“../bob” : All the tags beneath the parent of the current node  select=“/bob” : All the tags immediately beneath the root node  select=“//bob” : All the tags anywhere beneath the root node So in Example four, “//student” identified all the nodes anywhere beneath the root of the document that were tags.

XSL - XPath paths (Example Five)  XPath recognizes symbol as a shortcut to indicate that you’re referring to a node’s attributes instead of the tag name itself. Adding a textcolor=“...” attribute to the tag will now change the displayed color. (I use the tag to set the value of the tag’s color attribute.)

XSL - More tags to play with - insert a tag in the output stream  generates a named and parametrised tag: This is text produces the output This is text - inlines another XSL file  Replaces the tag with the contents of another XSL file at the specified URL.  Keep in mind that this may mean a new internet request, which could take time.

XSL - More tags to play with - conditionally select an element  The body of the tag is only added to the stream if the test condition in the test attribute is true.  Example:,...will match each instance of a tag under a tag and recurse on the title; but it will add a comma after every tag which is not the last in its list. See also: the tag, a more powerful form of conditional statement.  Used in conjunction with and.

Recap XSL:  Transforms documents from XML to another language  Can transform the document’s structure, as well as content XSL tags:  XPath:  *; node; node1/node2; node1//node2; //node;./node;../node

Bibliography O’Reilly’s XML Pocket Reference Robert Eckstein and Michel Casabianca; (c) 2001 O’Reilly.