1 overview of xsl. 2 outline we will use roger costello’s tutorial the purpose of this...

17
1 Overview of XSL

Upload: lucy-byrd

Post on 04-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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

1

Overview of XSL

Page 2: 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

2

Outline

• We will use Roger Costello’s tutorial

• The purpose of this presentation is To give a quick overview of XSLTo describe what is available in

Costello’s tutorial

Page 3: 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

3

Introduction and Motivation

Page 4: 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

4

Web Services

• A Web service is written using servlets, JSP or a similar technology

• The Web service interacts with databases using JDBC

• The Web service interacts with clients using a Web server

• The Web service may interact with other applications

Page 5: 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

5

The Traditional Approach• The Web service generates HTML pages in

order to interact with clients• Changing the HTML pages necessitates a

change in the Java code• Different clients (e.g., pc, palm-pilot, cell

phone) may require different HTML pagesDifferent versions of the Java code should be

maintained

• HTML is not suitable for information exchange, e.g., interacting with automated agents (knowbots)

Page 6: 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

6

The XML Approach: Separating Content from

Style• The Web service generates XML

documents• Automated agents get XML

documents in response to requests• Other clients get HTML pages that

are generated by adding style to the XML documentsIt is easy to implement different

styles for different clients

Page 7: 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

7

Where Should the Business Rules be

Implemented?• An example of a business rule

All products are now on sale at a discount of 10%

• Business rules may change frequently• Where should they be implemented?

Database applicationServlet or JSPXML transformation (by means of XSLT)

Page 8: 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

8

XML Transformations

• CSS can add style to XML, but it cannot transform an XML documentHow can you change the price of a

product in an XML document describing that product?

How can you add (to the XML document) the information that the product is on sale?

• XSLT can do just that

Page 9: 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

9

Even Just Adding Style May Require a Transformation

• Consider an XML document that describes several products and their prices

• How can you create a table with two columns – one for products and and one for prices?

• Cannot be done in CSS, but can be done in XSL

Page 10: 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

10

Different Types of Transformations

• Transform an XML document into An HTML page Another XML document A text file

• Roger Costello’s tutorial covers the three types (and more)

Page 11: 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

11

How to Transform?

• Write an XSL style sheet• Use an XSL processor to transform

the XML document according the XSL style sheet, or

• Add a Stylesheet PI (Processing Instruction) to the XML document and display the XML document using a browser (recent versions only, e.g., IE 6 or Netscape 7)

Page 12: 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

12

Roger Costello’s Tutorial

• It describes the XSL language• It gives many examples

There are actual files of the examplesEach example is in a separate folder

and it includes• An XML document• An XSL style sheet• The result of the transformation as

produced by an XSL processor

Page 13: 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

13

A Few Things About XSL• XSL is a high-level, functional

language• The syntax is a bit peculiar and

possibly confusing• An XSL style sheet is a valid XML

document Valid with respect to the XSL namespace

• Therefore, commands in XSL are XSL elements

Page 14: 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

14

How to Use the Examples• Since XSL is a high-level language,

XSL style sheets are relatively short and easy to understand

• It is easy to modify an existing style sheet into another style sheet with a similar functionalityThe many examples of Costello are

very useful as a starting point for writing your own style sheets

Page 15: 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

15

The Main Elements of XSL

• <xsl:value-of select=“xpath-expression“/>This element is for extracting values from the

given XML document

• <xsl:for-each select=“xpath-expression“/>This element is for looping

• <xsl:if test=“xpath-expression/>, <xsl:if test=“xpath-expression=value“/>, etc.This element is for conditional processing

Page 16: 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

16

Examples of Xpath Expressions

• /university/department/courseThis Xpath expression matches any path

that starts at the root, which is a university element, passes through a department element and ends in a course element

• ./department/course[@year=2002]This Xpath expression matches any path

that starts at the current element, continues to a child which is a department element and ends at a course element with a year attribute that is equal to 2002

Page 17: 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

17

How to Write a Style Sheet for Transforming XML to

HTML• Write a template in XHTML• Add some necessary elements and

PI (Processing Instructions)• Inside the XHTML template, use

XSL elements in order to extract values from the given XML document