18
XSL Extensible Stylesheet Language 1 Arvind pande M.E , MCTS http://arvindpandeblog.blogspot.in www.facebook.com/digitalpadm

Extensible Stylesheet language XSL basics

Embed Size (px)

Citation preview

Page 1: Extensible Stylesheet language XSL basics

XSLExtensible Stylesheet Language

1

Arvind pande M.E , MCTS

http://arvindpandeblog.blogspot.in

www.facebook.com/digitalpadm

Page 2: Extensible Stylesheet language XSL basics

XML

capturing and storing data

it handles data on cross platform

it makes data exchange easier

it provides data validation facilities

XSL

Transforms data from one format to another

provides formatting commands as per requirement

It add new content to xml

2

Page 3: Extensible Stylesheet language XSL basics

HTML

XML

(content)

XSL

(presentation)

XSL

Processor

EXtensible Style sheet Language 3

Page 4: Extensible Stylesheet language XSL basics

Transformation Language

XSL is a transformation language

it transforms a document written in one language (XML)into a document of another language (e.g., HTML)

Transformation Engine

(XSL Parser)

XSL

XML HTML

4

Page 5: Extensible Stylesheet language XSL basics

SOURCE OF DATA

(DATABASE)

APPLICATION PROGRAM

XML

XSL FILES XSL FILES XSL FILES

MOBILE COMPUTER

5

Page 6: Extensible Stylesheet language XSL basics

XSL Document Structure

xsl:stylesheet

template rule for the

documenttemplate rule for

a child element

action on the

documentaction on the child

element

6

Page 7: Extensible Stylesheet language XSL basics

XSL Document Structure

<?xml version=“1.0”?>

<xsl:stylesheet>

<xsl:template match=“/”>

[action]

</xsl:template>

<xsl:template match=“SCHOOL”>

[action]

</xsl:template>

<xsl:template match=“STUDENT”>

[action]

</xsl:template>

...

</xsl:stylesheet>

7

Page 8: Extensible Stylesheet language XSL basics

Template Rules

<xsl:template match=“pattern”>

[ action ]

</xsl:template>

8

Page 9: Extensible Stylesheet language XSL basics

An XSL style sheet consists of one or more set of rules that

are called templates.

Since an XSL style sheet is always begins with the

XML declaration:

<?xml version="1.0" ?>

The next element

<xsl: stylesheet version="1.0” xmlns:xsl =

“http://www.w3.org/1999/XSL/Transform”>

Each template contains rules to apply when a specified node is

matched.

The <xsl:template> element defines a template. The match="/"

attribute associates the template with the root of the XML source document.

<xsl:template>

9

Page 10: Extensible Stylesheet language XSL basics

Displaying XML on the web

XML documents do not carry information about how to display the data.

A generic XML document is rendered as raw XML text by most web browser.

In order to style the rendering in a browser with CSS or xsl , the XML document must include a reference to the stylesheet.

<?xml-stylesheet type="text/xsl" href="myTransform.xslt“ ? >

Extensible Stylesheet Language (XSL) can be used to alter the format of XML data, either into HTML or other formats that are suitable for a browser to display.

10

Page 11: Extensible Stylesheet language XSL basics

XSLT

XSLT is a language for

Transforming XML documents into XHTML documents

To other XML documents.

XSLT uses XPath to navigate in XML documents

XPath is a language for

navigating in XML documents.

It provides expression a for searching specific parts of XML

document.

11

Page 12: Extensible Stylesheet language XSL basics

In the transformation process, XSLT uses XPath to define

parts of the source document that should match one or

more predefined templates.

When a match is found, XSLT will transform the matching

part of the source document into the result document.

How Does it Work?12

Page 13: Extensible Stylesheet language XSL basics

<xsl: value-of>

The <xsl:value-of> element is used to extract the value of a

selected node.

The <xsl:value-of> Element

<xsl:value-of select="SCHOOL/student/roll"/>

The <xsl:value-of> element can be used to extract the

value of an XML element and add it to the output stream

of the transformation:

13

Page 14: Extensible Stylesheet language XSL basics

<xsl:for-each>

The <xsl:for-each> Element

The XSL <xsl:for-each> element can be used to select every XML

element of a specified node-set:

Filtering the Output

We can also filter the output from the XML file by adding a criterion

to the select attribute in the <xsl:for-each> element.

< xsl:for-each select=“College/ Student“ >

14

Page 15: Extensible Stylesheet language XSL basics

<xsl:sort>

The <xsl:sort> element is used to sort the output.Where to put the Sort Information

To sort the output, simply add an <xsl:sort> element inside

the <xsl:for-each> element in the XSL file:

<xsl:sort select="expression“

data-type="text|number”

order="ascending|descending"

case-order="upper-first|lower-first“ />

15

Page 16: Extensible Stylesheet language XSL basics

<xsl:if>

This element is used to put a conditional test against the content of the XML file.

<xsl:if test="expression">

...

...some output if the expression is

true...

...

</xsl:if>

<xsl:if test=“roll &gt; 111">

...

...some output if the expression is

true...

...

</xsl:if>

filter operators are: = (equal)

!= (not equal)

&lt; less than

&gt; greater than

16

Page 17: Extensible Stylesheet language XSL basics

<xsl:choose>

• The <xsl:choose> element is used in conjunction with <xsl:when> and <xsl:otherwise> to express multiple conditional tests.

The <xsl:choose> Element

Syntax

<xsl:choose>

<xsl:when test="expression">

... some output ...

</xsl:when>

<xsl:otherwise>

... some output ....

</xsl:otherwise>

</xsl:choose>

17

Page 18: Extensible Stylesheet language XSL basics

For Recent Technology , inventions , innovation &

To Download slides, programs, tutorials , assignments and more

Visit

http://arvindpandeblog.blogspot.in

http://www.facebook.com/digitalpadm

Thank you !