Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall 2005 1 XML Transformation: XSLT Semantic Web - Spring 2007 Computer.

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: Extensible Markup Language
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : 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.
CSE 190: Internet E-Commerce Lecture 17: XML, XSL.
XSL Transformations (XSLT) Meghasyam Bokam April’1 st, 2002.
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)
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.
Chapter 13 XML Concept of XML Simple Example of XML XML vs. HTML in Syntax XML Structure DTD and CDATA Sections Concept of SAX Processing Download and.
Using XSLT and XPath to Enhance HTML Documents Reference: Roger L. Costello
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.
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.
CPSC 203 Introduction to Computers Lab 39, 40 By Jie (Jeff) Gao.
16-1 The World Wide Web The Web An infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that information.
XML and XSL Institutional Web Management 2001: Organising Chaos.
CREATED BY ChanoknanChinnanon PanissaraUsanachote
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.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
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,
Advanced Information Retreival Chap. 06: Text and Multimedia Languages and Properties (Introduction, Metadata and Text) 6.4.
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.
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.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
Lecture 11 XSL Transformations (part 1: Introduction)
Waqas Anwar Next SlidePrevious Slide. Waqas Anwar Next SlidePrevious Slide XML XML stands for EXtensible Markup Language.
 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.
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.
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.
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.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
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.
Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall XML Transformation: XSLT Semantic Web - Fall 2005 Computer.
XSLT I Robin Burke ECT 360. Outline History / Terminology XSLT processing XSLT syntax XPath XSLT basics Lab.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
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.
Apache Cocoon – XML Publishing Framework 데이터베이스 연구실 박사 1 학기 이 세영.
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.
XSLT: The XML transformation language
Reference: cit /Lectures/xslt.ppt
Applying eXtensible Style Sheets (XSL)
XSL XSLT and XPath 24-Feb-19.
XSL XSLT and XPath.
More XML XML schema, XPATH, XSLT
Presentation transcript:

Semantic web course – Computer Engineering Department – Sharif Univ. of Technology – Fall XML Transformation: XSLT Semantic Web - Spring 2007 Computer Engineering Department Sharif University of Technology

Semantic web - Computer Engineering Dept. - Spring Outline Fundamentals of XSLT XPath Cocoon

Semantic web - Computer Engineering Dept. - Spring XSLT XSLT stands for Extensible Stylesheet Language Transformations It is used to transform XML documents into other kinds of documents, e.g. HTML, PDF, XML, … XSLT uses two input files: –The XML document containing the actual data –The XSL document containing both the “framework” in which to insert the data, and XSLT commands to do so

Semantic web - Computer Engineering Dept. - Spring XSLT Architecture Source XML doc XSL stylesheet XSL processor Target Document

Semantic web - Computer Engineering Dept. - Spring Some special transforms XML to HTML— for old browsers XML to LaTeX—for TeX layout XML to SVG—graphs, charts, trees XML to tab-delimited—for db/stat packages XML to plain-text—occasionally useful XML to XSL-FO formatting objects

Semantic web - Computer Engineering Dept. - Spring XSLT Data Model XSLT reads an XML documents as a source tree Transforms the documents into a result tree Transformations are specified in a stylesheet To navigate the tree XSLT uses XPath

Semantic web - Computer Engineering Dept. - Spring Introduction to XPath XPath is a syntax for addressing parts of an XML document by –describing paths through the document hierarchy –specifying constraints to match against the document's structure XSL uses XPath expressions to –determine which elements match a template –select nodes upon which to perform operations

Semantic web - Computer Engineering Dept. - Spring XPath Basics XPath expressions superficially resemble UNIX pathnames, e.g. poem/stanza/line refers to "all line elements which are children of stanza elements which are children of poem elements" XPath expressions are evaluated relative to a "context node", which is analogous to the "current working directory" in UNIX or DOS. The XPath expression for this is "."

Semantic web - Computer Engineering Dept. - Spring XPath Basics: a Simple Example Consider the following XML document: Roses Ima Poet Roses are red violets are blue I'm a poet and you're not!

Semantic web - Computer Engineering Dept. - Spring XPath Basics: a Simple Example (cont.) The XPath " poem/stanza/line " selects Roses Ima Poet Roses are red violets are blue I'm a poet and you're not!

Semantic web - Computer Engineering Dept. - Spring XPath Basics: wildcards The XPath " poem/stanza/* " selects Roses Ima Poet Roses are red violets are blue I'm a poet and you're not!

Semantic web - Computer Engineering Dept. - Spring XPath Basics: descendants The XPath " poem//punch " selects: Roses Ima Poet Roses are red violets are blue I'm a poet and you're not!

Semantic web - Computer Engineering Dept. - Spring XPath Basics: sequencing " poem/stanza/line[1] " selects: Roses Ima Poet Roses are red violets are blue I'm a poet and you're not!

Semantic web - Computer Engineering Dept. - Spring XPath Basics: sequencing (cont.) " poem/stanza/line[position() = last()] " selects: Roses Ima Poet Roses are red violets are blue I'm a poet and you're not!

Semantic web - Computer Engineering Dept. - Spring XPath Basics: selecting text nodes " poem/author/text() " selects: Roses Ima Poet Roses are red violets are blue I'm a poet and you're not!

Semantic web - Computer Engineering Dept. - Spring XPath Basics: conditionals " poem/stanza[punch] " selects: Roses Ima Poet Roses are red violets are blue I'm a poet and you're not!

Semantic web - Computer Engineering Dept. - Spring XPath Basics: conditionals: equality “ //line[text()="I'm a poet"] ” Roses Ima Poet Roses are red violets are blue I'm a poet and you're not!

Semantic web - Computer Engineering Dept. - Spring A simple XSL example File data.xml : Hello World! File render.xsl :

Semantic web - Computer Engineering Dept. - Spring Stylesheet (.xsl file) It is a well-formed XML document It is a collection of template rules A template rule consists of pattern and a template Pattern is specified in Xpath and locates the node of the XML tree. The located node is replaced by the template in the result tree

Semantic web - Computer Engineering Dept. - Spring The.xsl file An XSLT document has the.xsl extension The XSLT document begins with: Contains one or more templates, such as:... And ends with:

Semantic web - Computer Engineering Dept. - Spring Finding the message text The template says to select the entire file –You can think of this as selecting the root node of the XML tree Inside this template, – selects the message child –Alternative Xpath expressions that would also work:./message /message/text()./message/text()

Semantic web - Computer Engineering Dept. - Spring Putting it together The XSL was: The chooses the root The is written to the output file The contents of message is written to the output file The is written to the output file The resultant file looks like: Hello World!

Semantic web - Computer Engineering Dept. - Spring How XSLT works The XML text document is read in and stored as a tree of nodes The template is used to select the entire tree The rules within the template are applied to the matching nodes, thus changing the structure of the XML tree –If there are other templates, they must be called explicitly from the main template Unmatched parts of the XML tree are not changed After the template is applied, the tree is written out again as a text document

Semantic web - Computer Engineering Dept. - Spring Where XSLT can be used A server can use XSLT to change XML files into HTML files before sending them to the client A modern browser can use XSLT to change XML into HTML on the client side –This is what we will mostly be doing in this class Most users seldom update their browsers –If you want “everyone” to see your pages, do any XSL processing on the server side

Semantic web - Computer Engineering Dept. - Spring Modern browsers Internet Explorer 6 best supports XML Netscape 6 supports some of XML Internet Explorer 5.x supports an obsolete version of XML –If you must use IE5, the initial PI is different (you can look it up if you ever need it)

Semantic web - Computer Engineering Dept. - Spring xsl:value-of selects the contents of an element and adds it to the output stream –The select attribute is required –Notice that xsl:value-of is not a container, hence it needs to end with a slash Example (from an earlier slide):

Semantic web - Computer Engineering Dept. - Spring xsl:for-each xsl:for-each is a kind of loop statement The syntax is Text to insert and rules to apply Example: to select every book ( //book ) and make an unordered list ( ) of their titles ( title ), use:

Semantic web - Computer Engineering Dept. - Spring Filtering output You can filter (restrict) output by adding a criterion to the select attribute’s value: This will select book titles by Terry Pratchett

Semantic web - Computer Engineering Dept. - Spring Filter details Here is the filter we just used: author is a sibling of title, so from title we have to go up to its parent, book, then back down to author This filter requires a quote within a quote, so we need both single quotes and double quotes Legal filter operators are: = != < > –Numbers should be quoted, but apparently don’t have to be

Semantic web - Computer Engineering Dept. - Spring But it doesn’t work right! Here’s what we did: This will output and for every book, so we will get empty bullets for authors other than Terry Pratchett There is no obvious way to solve this with just xsl:value-of

Semantic web - Computer Engineering Dept. - Spring xsl:if xsl:if allows us to include content if a given condition (in the test attribute) is true Example: This does work correctly!

Semantic web - Computer Engineering Dept. - Spring xsl:choose The xsl:choose... xsl:when... xsl:otherwise construct is XML’s equivalent of Java’s switch... case... default statement The syntax is:... some code some code... xsl:choose is often used within an xsl:for-each loop

Semantic web - Computer Engineering Dept. - Spring xsl:sort You can place an xsl:sort inside an xsl:for-each The attribute of the sort tells what field to sort on Example: by –This example creates a list of titles and authors, sorted by author

Semantic web - Computer Engineering Dept. - Spring xsl:text... helps deal with two common problems: –XSL isn’t very careful with whitespace in the document This doesn’t matter much for HTML, which collapses all whitespace anyway (though the HTML source may look ugly) gives you much better control over whitespace; it acts like the element in HTML –Since XML defines only five entities, you cannot readily put other entities (such as ) in your XSL &nbsp; almost works, but is visible on the page Here’s the secret formula for entities: &nbsp;

Semantic web - Computer Engineering Dept. - Spring Creating tags from XML data Suppose the XML contains Dr. Abolhassani's Home Page And you want to turn this into Dr. Abolhassani's Home Page We need additional tools to do this!

Semantic web - Computer Engineering Dept. - Spring Creating tags--solution 1 Suppose the XML contains Dr. Abolhassani's Home Page adds the named attribute to the enclosing tag The value of the attribute is the content of this tag Example: Result: Dr. Abolhassani's Home Page

Semantic web - Computer Engineering Dept. - Spring Creating tags--solution 2 Suppose the XML contains Dr. Abolhassani's Home Page An attribute value template (AVT) consists of braces { } inside the attribute value The content of the braces is replaced by its value Example: Result: Dr. Abolhassani's Home Page

Semantic web - Computer Engineering Dept. - Spring Modularization Modularization--breaking up a complex program into simpler parts--is an important programming tool –In programming languages modularization is often done with functions or methods –In XSL we can do something similar with xsl:apply-templates For example, suppose we have a DTD for book with parts titlePage, tableOfContents, chapter, and index –We can create separate templates for each of these parts

Semantic web - Computer Engineering Dept. - Spring Book example Table of Contents Etc.

Semantic web - Computer Engineering Dept. - Spring xsl:apply-templates The element applies a template rule to the current element or to the current element’s child nodes If we add a select attribute, it applies the template rule only to the child that matches If we have multiple elements with select attributes, the child nodes are processed in the same order as the elements

Semantic web - Computer Engineering Dept. - Spring Applying templates to children XML Gregory Brill by With this line: XML by Gregory Brill Without this line: XML

Semantic web - Computer Engineering Dept. - Spring Tools for XSL Development There are a number of free and commercial XSL tools available –XSLT processors: MSXML, which currently supports the latest XSLT specification (native Win32) Xalan from Apache (C++, Java) –Editors and browsers Internet Explorer 6.0 XML Spy (commercial)

Semantic web - Computer Engineering Dept. - Spring Cocoon Cocoon is Apache’s dynamic XML Publishing Framework. Cocoon uses XSLT. Cocoon allows separation of content, logic and presentation. making sure people can interact and collaborate on a project, without stepping on each other toes, and component-based web development. Cocoon is a web-application that runs using Apache Tomcat (Cocoon.war).

Semantic web - Computer Engineering Dept. - Spring What Cocoon can do

Semantic web - Computer Engineering Dept. - Spring Cocoon Pipeline Cocoon introduced the idea of a pipeline to handle a request. A pipeline is a series of steps for processing a particular kind of content.

Semantic web - Computer Engineering Dept. - Spring Cocoon processing

Semantic web - Computer Engineering Dept. - Spring Separating content and layout

Semantic web - Computer Engineering Dept. - Spring Sitemap

Semantic web - Computer Engineering Dept. - Spring Sitemap (cont.)

Semantic web - Computer Engineering Dept. - Spring Defining a pipeline

Semantic web - Computer Engineering Dept. - Spring Defining a pipeline (cont.)

Semantic web - Computer Engineering Dept. - Spring Complex pipeline

Semantic web - Computer Engineering Dept. - Spring Matching a request

Semantic web - Computer Engineering Dept. - Spring Other features Selectors components Multi-channel capabilities Actions components Readers XSP Content aggregation Views Form processing

Semantic web - Computer Engineering Dept. - Spring References Specifications: – – – – An excellent XSLT tutorial: – Another tutorial: – Microsoft (MSXML3): – Saxon: – Xalan: – Cocoon: