eXtensible Stylesheet Language

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.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSLT (eXtensible Stylesheet Language Transformation) 1.
XSL XSLT and XPath 11-Apr-17.
XML and XSL Transforming your XML documents with eXtensible Stylesheet Language Transformations [Optional Lecture]
Rendering XML documents with XSL The most powerful approaches to rendering XML documents involve using XSL (eXtensible Stylesheet Language) XSL enables.
We Need Smart XML Processing HTML has ultra-complex semantics XML has no semantics Something must bridge the gap  A program ?  A clear set of data semantics?
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 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)
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.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
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,
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.
XML Part 2 Josh Steele CS 6704, Spring XML Part 2 XSL/XSLT –Structure Revisited –Definition –Example –Components XML’s Linking Languages XML’s Uses.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
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.
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.
XML, XSL, and SOAP Building Object Systems from Documents CSC/ECE 591o Summer 2000.
Unit 3 — Advanced Internet Technologies Lesson 11 — Introduction to XSL.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
 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.
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.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
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 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
.
XSLT: The XML transformation language
XML Introduction Bill Jerome.
Displaying XML Data with XSLT
Reference: cit /Lectures/xslt.ppt
Using XSLT and XPath to Transform XML Documents
XML in Web Technologies
XSLT 1.0.
Extensible Markup Language XML
ACG 4401 XSLT Extensible Stylesheet Language for Transformations
XML Data Introduction, Well-formed XML.
Applying eXtensible Style Sheets (XSL)
XML WITH CSS.
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.
Unit 6 - XML Transformations
Presentation transcript:

eXtensible Stylesheet Language COMP3220 Web Infrastructure COMP6218 Web Architecture Dr Nicholas Gibbins – nmg@ecs.soton.ac.uk 2017-2018

The Problem How do you maintain different versions of a document for presentation on different systems that: Have different presentation characteristics (screen size, etc)? Require different document formats? XSL is a family of XML-based technologies designed to address this problem

eXtensible Stylesheet Language XSL Transformations (XSLT) XML-based language for describing transformations from one XML- based language to another XML Path Language (XPath) Language for referring to parts of an XML document XSL Formatting Objects (XSL-FO) XML vocabulary for specifying formatting semantics

XML processing printed document source document web page ebook

XSL processing in theory data.dtd FO.dtd printed document data.xml XSL Transform FO.xml XSL Formatting web page XSL-FO ebook data.xsl XSLT + XPath

XSL processing in practice doc.css data.dtd CSS printed document data.xml XSL Transform doc.html Browser web page HTML ebook data.xsl XSLT + XPath

Example input <?xml version="1.0" encoding="UTF-8"?> <contacts> <name>My address list</name> <card> <name>Fred Foo</name> <email>fred@example.org</email> <tel type="work">01234567890</tel> </card> <card> <name>Jill Bar</name> <email>jill@example.org</email> <tel type="home">02345678901</tel> </card> </contacts>

Example output <html xmlns="http://www.w3.org/TR/xhtml1/strict"> <head> <title>My address list</title> </head> <body> <h1>My address list</h1> <div> <h2>Fred Foo</h2> <p>Email: <a href="mailto:fred@example.org">fred@example.org</a></p> <p>Telephone: 01234567890</p> </div> <div> <h2>Jill Bar</h2> <p>Email: <a href="mailto:jill@example.org">jill@example.org</a></p> <p>Telephone: 02345678901</p></div> </body> </html>

XSL stylesheets An XSL stylesheet consists of a number of templates Each template: Matches an element in the original document using XPath Specifies the new content with which the element is to be replaced

XPath Expression language for specifying nodes (elements, attributes) within an XML document Specifies nodes using a path through the hierarchy of the document Can be absolute (from the root) or relative (from current position)

XPath expressions E Selects all nodes with the name E / Selects from the root node // Selects nodes anywhere under the current node . Selects the current node .. Selects the parent of the current node @ Selects attributes

XPath expression examples contacts Selects all contacts elements /contacts Selects the root contacts element contacts/card Select all card elements that are children of contacts //card Select all card elements contacts//name Select all name elements that are descendants of contacts //tel/@lang Select type attribute on all tel elements

xsl:template match attribute contains XPath expression that identifies an element or elements Content of element is either output markup, or other XSL directives <xsl:template match="/"> ... </xsl:template>

xsl:apply-templates Used within body of a template Recursively applies templates to children of the element select attribute identifies target child node using XPath <xsl:apply-templates select=”..."/>

xsl:for-each Loops over every matching element select attribute identifies target node set <xsl:for-each select=”..."> ... </xsl:for-each>

xsl:value-of Extracts the value of an XML element and uses it in the output document select attribute used to identify element <xsl:value-of select=”..."/>

XSLT Example

XSLT example – input <?xml version="1.0" encoding="UTF-8"?> <contacts> <name>My address list</name> <card> <name>Fred Foo</name> <email>fred@example.org</email> <tel type="work">01234567890</tel> </card> <card> <name>Jill Bar</name> <email>jill@example.org</email> <tel type="home">02345678901</tel> </card> </contacts>

XSLT example – output <html xmlns="http://www.w3.org/TR/xhtml1/strict"> <head> <title>My address list</title> </head> <body> <h1>My address list</h1> <div> <h2>Fred Foo</h2> <p>Email: <a href="mailto:fred@example.org">fred@example.org</a></p> <p>Telephone: 01234567890</p> </div> <div> <h2>Jill Bar</h2> <p>Email: <a href="mailto:jill@example.org">jill@example.org</a></p> <p>Telephone: 02345678901</p></div> </body> </html>

XSLT example – using stylesheet <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="contacts.xsl" version="1.0"?> <contacts> <name>My address list</name> <card> <name>Fred Foo</name> <email>fred@example.org</email> <tel>01234567890</tel> </card> <card> <name>Jill Bar</name> <email>jill@example.org</email> <tel>02345678901</tel> </card> </contacts>

XSLT example – stylesheet <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict"> ... </xsl:stylesheet>

XSLT example – templates <xsl:template match="/"> <html> <head> <title><xsl:value-of select="/contacts/name"/></title> </head> <body> <h1><xsl:value-of select="/contacts/name"/></h1> <xsl:for-each select="/contacts/card"> <div> <xsl:apply-templates select="name"/> <xsl:apply-templates select="email"/> <xsl:apply-templates select="tel"/> </div> </xsl:for-each> </body> </html> </xsl:template>

XSLT example – templates <xsl:template match="name"> <h2><xsl:value-of select="."/></h2> </xsl:template> <xsl:template match="tel"> <p>Telephone: <xsl:value-of select="."/></p> </xsl:template> <xsl:template match="email"> <p>Email: <a href="mailto:{.}"><xsl:value-of select="."/></a></p> </xsl:template>

XSL versus CSS Considering CSS... Pros Cons Simple (relatively) Cascading recognises different needs of users and authors Cons Unable to modify document structure Bad for XML data

XSL versus CSS Considering XSL: Pros Cons Able to modify and transform document structure Better for data Cons Complex (relatively) Cumbersome for ordinary documents No consideration of differing needs of users versus authors

Next Lecture: Further HTTP