Post on 14-Feb-2017
XSLExtensible Stylesheet Language
1
Arvind pande M.E , MCTS
http://arvindpandeblog.blogspot.in
www.facebook.com/digitalpadm
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
HTML
XML
(content)
XSL
(presentation)
XSL
Processor
EXtensible Style sheet Language 3
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
SOURCE OF DATA
(DATABASE)
APPLICATION PROGRAM
XML
XSL FILES XSL FILES XSL FILES
MOBILE COMPUTER
5
XSL Document Structure
xsl:stylesheet
template rule for the
documenttemplate rule for
a child element
action on the
documentaction on the child
element
6
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
Template Rules
<xsl:template match=“pattern”>
[ action ]
</xsl:template>
8
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
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
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
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
<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
<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
<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
<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 > 111">
...
...some output if the expression is
true...
...
</xsl:if>
filter operators are: = (equal)
!= (not equal)
< less than
> greater than
16
<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
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 !