Professional Documents
Culture Documents
Extensible Stylesheet Language Transformations
Extensible Stylesheet Language Transformations
Transformations
1
XSL
2
XML
HTML
XSL
XSL
CSS
HTML Document
displayed in the web
XSL - Style Sheet Declaration
5
OR
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
XSL - Style Sheet Declaration
6
the official W3C XSLT namespace. If you use this namespace, you
must also include the attribute version="1.0".
Link the XSL Style Sheet to the XML
7
<?xml-stylesheet type="text/xsl" href= "Stylesheet.xsl"?>
Example for XSL
8
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="breakfast_menu">
<html>
<title></title>
<body>
<table border="1">
<thead style="text-align:left" width="50%">
<td>Name</td>
<td>Price</td>
</thead>
<xsl:for-each select="food">
<xsl:sort select="price" order="ascending"/>
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Difference Between XSL and CSS
9
Pattern Pattern
– Sorting
– Operators
– Filtering
Selecting Nodes
12
Expression Description
nodename Selects all nodes with the name "nodename"
/ Selects from the root node
// Selects nodes in the document from the current node that
match the selection no matter where they are
. Selects the current node
.. Selects the parent of the current node
@ Selects attributes
Filtering and Logical Operators
13
An XSL style sheet consists of one or more set of rules that are called
templates.
<xsl:template match="/">
<!– XSL content go here -->
</xsl:template>
xsl:import
All the different style sheets imported are arranged in an import tree.
sheet is imported
xsl:value-of
17
<xsl:value-of select="name"/>
xsl:for-each
18
<xsl:for-each select="food">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
xsl:text
19
to the output.
<xsl:choose>
<xsl:when test="price > 8">
<td style="color:red"><xsl:value-of select="name"/></td>
<td style="color:red"><xsl:value-of select="price"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="price"/></td>
</xsl:otherwise>
</xsl:choose>
xsl:sort
23
– Node Sets
– Booleans
– Strings
– Numbers
Node Sets
25
namespace-uri(), root().
Node Sets
26
Name Description
fn:name() Returns the name of the current node or the
fn:name(nodeset) first node in the specified node set
fn:local-name() Returns the name of the current node or the
fn:local- first node in the specified node set – without
name(nodeset) the namespace prefix
fn:namespace-uri()
fn:namespace- Returns the namespace URI of the current
uri(nodeset) node or the first node in the specified node set
Name Description
fn:boolean(arg) Returns a boolean value for a number, string, or node-
set
The argument is first reduced to a Boolean value by
applying the boolean() function. Returns true if the
fn:not(arg) boolean value is false, and false if the boolean value is
true
Example: not(true())
Result: false
Returns the boolean value true
fn:true() Example: true()
Result: true
Returns the boolean value false
fn:false() Example: false()
Result: false
Strings
28
Name Description
Returns the string value of the argument. The
argument could be a number, boolean, or
fn:string(arg) node-set
Example: string(314)
Result: "314"
Returns -1 if comp1 is less than comp2, 0 if
comp1 is equal to comp2, or 1 if comp1 is
fn:compare(comp1,comp2) greater than comp2 according to the rules of
the collation that is used)
Example: compare('ghi', 'ghi')
Result: 0
fn:concat(string,string, Returns the concatenation of the strings
...) Example: concat('XPath ','is ','FUN!')
Result: 'XPath is FUN!'
Strings
30
Name Description
Returns the substring from the start position to
fn:substring(string,start the specified length. Index of the first character
,len) is 1. If length is omitted it returns the substring
fn:substring(string,start from the start position to the end
) Example: substring('Beatles',1,4)
Result: 'Beat’
Returns the length of the specified string. If
fn:string-length(string) there is no string argument it returns the length
fn:string-length() of the string value of the current node
Example: string-length('Beatles')
Result: 7
Converts string1 by replacing the characters in
fn:translate(string1,stri string2 with the characters in string3
ng2,string3) Example: translate('12:30','0123','abcd')
Result: 'bc:da'
Numbers
31
Name Description
Returns the numeric value of the argument. The argument could be a
fn:number(arg) boolean, string, or node-set
Example: number('100')
Result: 100
Returns the absolute value of the argument
fn:abs(num) Example: abs(-3.14)
Result: 3.14
Returns the smallest integer that is greater than the number argument
fn:ceiling(num) Example: ceiling(3.14)
Result: 4
Returns the largest integer that is not greater than the number argument
fn:floor(num) Example: floor(3.14)
Result: 3
Rounds the number argument to the nearest integer
fn:round(num) Example: round(3.14)
Result: 3
Q&A
33