Images

XSL - PART V


XSL
EXtensible Stylesheet Language(XSL) is an standard from theW3C for describing a style sheet for XML documents. It is the XMLcounterpart to the Cascading Style Sheets (CSS) in HTML and is compatible with CSS2.
XSL is made up of three components: (1) XSL Transformations (XSLT) is the processing language for XSL. It is used to convert XML documents into HTML or other document types and may be used independently of XSL. (2) XML Path Language (XPath) is used to identify and select tagged elements within an XML document, and (3)XSL Formatting Objects (XSL-FO) provides the format vocabulary.
An XSLT is the transformation language, which lets you define a transformation from XMLinto some other format.
For example, you might use XSLT to produce HTML or a different XML structure. You could even use it to produce plain text or to put the information in some other document format.
eXtensible Stylesheet Language Transformation, converts an XML document into another format such as HTMLPDF or text.


XSL Sorting
Attributes
<xsl:attribute name="qname" namespace="URI" >

</xsl:attribute>
The xsl:attribute element allows you to create an attribute node, define a value, and add it to the output. In simple terms, you are creating a custom attribute whose value can be displayed.
After a child node has been added to an element, no additional attributes can be added to the parent node. This restriction is required so that the XSL processor does not have to store the entire result tree in memory while searching for additional attributes.
The related xsl:attribute-set can serve as a container for a collection of xsl:attributeelements.

This is not a self-closing element. The separate closing element is mandatory.
name="qname"
The mandatory name attribute is the qname of the attribute to be displayed in output. A qname is a qualified name that is composed of an optional namespace prefix, a colon, which is only present if there is a prefix, and a mandatory XML name (for example, xsl:zipcode or zipcode).
The name is one of a very few attributes that can be set to an expression that is computed at run-time. (Such attributes are interpreted as Attribute Value Templates.) The syntax for doing this is demonstrated with the following code fragment:
<xsl:attribute name="{$att_name}" />
namespace="URI"
The optional namespace attribute is the namespace URI (Universal Resource Identifier) of the attribute. The namespace is one of a very few attributes that can be set to an expression that is computed at run-time. (Such attributes are interpreted as Attribute Value Templates.)
Attribute set
<xsl:attribute-set name="qname" use-attribute-sets="qnames" >

</xsl:attribute-set>
The xsl:attribute-set element defines and names a set containing zero or more xsl:attribute elements. Each of the xsl:attribute elements are applied to the output in the order that they occur inside the xsl:attribute-set element.
An xsl:attribute element allows you to create an attribute node, define a value, and add it to the output.
The xsl:attribute-set element can only be a child of the xsl:stylesheet or the xsl:transform elements. The concept is that you can create a set of attributes that can be applied more than once by simply calling the attribute set by name.
This is not a self-closing element. The separate closing element is mandatory.
name="qname"
The mandatory name attribute is the name of the attribute set. It must be a qname. A qname is a qualified name that is composed of an optional namespace prefix, a colon, which is only present if there is a prefix, and a mandatory XML name (for example, xsl:zipcode or zipcode).
use-attribute-sets="qnames"
The optional use-attribute-sets attribute is a white-space-delimited list of one or more qnames of attribute sets. In other words, it is a collection of attribute set names. Each of the xsl:attribute elements in all of the attribute sets are applied to the output in the order in which they occur in the use-attribute-sets attribute.
This is done by adding the use-attribute-sets attribute to the HTML tag or XSLT element using the following syntax:
<table xsl:use-attribute-sets="name">
<xsl:copy use-attribute-sets="name"> ... </xsl:copy>
We use the eBIZ.com Staff List XML file for our example with the following header:

<?xml-stylesheet type="text/xsl" href="xslt_example_attributeset.xsl"?> 

and we name it:
xslt_example_attributeset.xml
<?xml version="1.0" encoding="iso-8859-1"?>

<?xml-stylesheet type="text/xsl" href="xslt_example_attribute_set.xsl"?>

     <ebiz>
		<employee_details phno="0089090">

			<emp_id>eBIZTECH001</emp_id>

			<fname>Mr Aman Kumar</fname>

			<lname>Singh</lname>

			<department>TECHICAL[Java]</department>

			<designation>Sr. Developer</designation>

			<phone> 32942</phone>

			<address>Sector 44, Noida</address>

		</employee_details>

		<employee_details>

			<emp_id>eBIZCSS001</emp_id>

			<fname>Mrs Sunita</fname>

			<lname>Singhania</lname>

			<department>Customer Support[Web Assis
t]</department>

			<designation>CCE</designation>

			<phone> 000000</phone>

			<address>Sector 66, Gurgaon</address>

		</employee_details>

		<employee_details>

			<emp_id>eBIZAC001</emp_id>

			<fname>Miss Amisha</fname>

			<lname>Mishra</lname>

			<department>Accounts</department>

			<designation>Jr. Accountant</designation>

			<phone> 32942</phone>

			<address>Sector 66, Rohni</address>
</employee_details>

		<employee_details>

			<emp_id>eBIZAC001</emp_id>

			<fname>ANITA</fname>

			<lname>Mishra</lname>

			<department>Accounts</department>

			<designation>Jr. Accountant</designation>

			<phone> 09999 </phone>

			<address>Sector 66, Noida</address>

		</employee_details>

		
		
		<employee_details>

			<emp_id>eBIZAC001</emp_id>

			<fname>ANKITA</fname>

			<lname>DUBEY</lname>

			<department>Accounts</department>

			<designation>Jr. Accountant</designation>

			<phone>032942 </phone>

			<address>Sector 99, Noida</address>

		</employee_details>

		<employee_details>

			<emp_id>eBIZAC001</emp_id>

			<fname>AKSHITA</fname>

			<lname>Jaiswal </lname>

			<department>TECHICAL[Java]</department>

			<designation>Jr. DEVELOPER</designation>

			<phone> (+91)99990</phone>

			<address>Sector 66, Noida</address>

		</employee_details>

		<employee_details>

			<emp_id>eBIZAC001</emp_id>

			<fname>Shweta</fname>

			<lname>Agrwal</lname>

			<department>TECHICAL[Java]</department>

			<designation>Jr. Programmer</designation>

			<phone> 32942</phone>

			<address>Sector 66, Noida</address>

		</employee_details>
</ebiz>
In this example we set the border, cellpadding, and cellspacing values for a table. We only apply the attribute set to one table, but it can be applied to any number of tables to give a similar look.
Code for xslt_example_attributeset.xsl:
<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE xsl:stylesheet  [

	<!ENTITY nbsp   " ">

	<!ENTITY copy   "©">

	<!ENTITY reg    "®">

	<!ENTITY trade  "™">

	<!ENTITY mdash  "—">

	<!ENTITY ldquo  "“">

	<!ENTITY rdquo  "”"> 

	<!ENTITY pound  "£">

	<!ENTITY yen    "¥">

	<!ENTITY euro   "€">
]>
<xsl:stylesheet version="1.0" 

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="phone address" />

<xsl:preserve-space elements="fname" />

<xsl:output method="html" encoding="iso-8859-1" 

doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 

doctype-system="http://

www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:attribute-set name="table1" >

<xsl:attribute name="border">
2
</xsl:attribute>
 
<xsl:attribute name="bgcolor">

"#9999FF"

</xsl:attribute>

<xsl:attribute name="border">
1
</xsl:attribute>

<xsl:attribute name="cellpadding">
3
</xsl:attribute>

<xsl:attribute name="cellspacing">
1
</xsl:attribute>

</xsl:attribute-set>

<xsl:template match="/">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<script>

var i=0;

function mm() {

i+=1;
document.data.srno.innerHTML=""+i;
}
</script> 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

<title>Sample XSL Document</title>

<style type="text/css">

<xsl:comment>

.style3 {font-family: Geneva, Arial, Helvetica, sans-serif; color: #0033FF; }

</xsl:comment>

</style>

</head>

<body>

	

<table width="59%" id="data" xsl:use-attribute-sets="table1">

  <tr>

    <td width="9%" nowrap="nowrap" bgcolor="#6699FF">

<strong>Sr no </strong></td>

    <td width="22%" bgcolor="#6699FF">

<strong>Employee ID </strong></td>

	<td width="30%" bgcolor="#6699FF">

<strong>Name</strong></td>
    
    <td width="20%" bgcolor="#6699FF"><strong>Department
</strong></td>
   
    <td width="19%" bgcolor="#6699FF"><strong>Designation

</strong></td>

	<td width="19%" nowrap="nowrap" bgcolor="#6699FF">

<strong>Phone No </strong></td>

	<td width="19%" nowrap="nowrap" bgcolor="#6699FF"

><strong>Address </strong></td>

  </tr>
<xsl:for-each select="ebiz/employee_details">

	<tr>
<td><span class="style3">.

      <script>i=i+1;document.write(i);</script>

    </span></td>

     <td nowrap="nowrap"><span class="style3">

<xsl:value-of select="emp_id" /></span></td>

	 <td nowrap="nowrap"><span class="style3"

><xsl:value-of select="fname"> </xsl:value-of>   

 <xsl:value-of select="lname"></xsl:value-of></span></td>
   
    <td nowrap="nowrap"><xsl:value-of select="department" /></td>
    
    <td nowrap="nowrap"><xsl:value-of select="designation" /></td>

	<td nowrap="nowrap"> 

 <xsl:value-of select="phone" /></td	>

	<td nowrap="nowrap"><xsl:value-of select="address"/></td>

  </tr></xsl:for-each>

</table>
 
</body>

</html>

</xsl:template>

</xsl:stylesheet> 
Output: Click to view the Resulting XML file or the XSL file.

XSL Sorting
Sorting and Numbering
<xsl:sort case-order="upper-first" | "lower-first" data-type="number" "qname" | "text"

lang="language-code" order="ascending" | " descending" select="expression" >

</xsl:sort>
The xsl:sort element is used to define a sort key. This sort key determines the order in which selected nodes are processed by the xsl:for-each or xsl:apply-templates elements.
A sort can be based upon more than one xsl:sort element. Each sort is applied in the order in which it occurs. Duplicate values are left in document order. After the first sort has reordered the nodes, the second sort is applied to any nodes that had duplicate values in the first sort. The third sort is applied to any nodes that had duplicate values in the second sort, and so on.
This is not a self-closing element. The separate closing element is mandatory.
case-order="upper-first" | "lower-first"
The optional case-order attribute dictates whether the sort will have upper or lower case letters listed first in the sort. The default is to list upper case first.
data-type="number" | "qname" | "text"
The optional data-type attribute specifies the data type of the strings. There are only three permitted types:
ValueEffect
numberThe sort key is converted to a number.
qnameThe sort is based upon a user-defined data type.
textThe sort is alphabetic.
lang="language-code"
The optional lang attribute is set to an Attribute Value Template or a string that dictates the language code which in turn specifies the language alphabet to be used for the sort. Clearly, the alphabet and numbers being used will determine the sort order. The default language is set by the operating system environment.
order="ascending" | " descending"
The optional order attribute dictates whether the sort is in increasing or decreasing order. The default is ascending.
select="expression"
The optional select attribute is an expression that defines the key upon which the sort will be based. The expression is evaluated and converted to a string that is used as the sort key. If no select attribute is provided (hence, no sort key), the selected nodes are sorted in document order.
<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE xsl:stylesheet  [

	<!ENTITY nbsp   " ">

	<!ENTITY copy   "©">

	<!ENTITY reg    "®">

	<!ENTITY trade  "™">

	<!ENTITY mdash  "—">

	<!ENTITY ldquo  "“">

	<!ENTITY rdquo  "”"> 

	<!ENTITY pound  "£">

	<!ENTITY yen    "¥">

	<!ENTITY euro   "€">
]>
<xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="phone address" />

<xsl:preserve-space elements="fname" />

<xsl:output method="html" encoding="iso-8859-1" 

doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"

 doctype-system="http://www.w3.org/

TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:attribute-set name="table1" >

<xsl:attribute name="border">
2
</xsl:attribute>
<xsl:attribute name="bgcolor">

"#9999FF"

</xsl:attribute>

<xsl:attribute name="border">

1
</xsl:attribute>

<xsl:attribute name="cellpadding">

3
</xsl:attribute>

<xsl:attribute name="cellspacing">
1
</xsl:attribute>

</xsl:attribute-set>

<xsl:template match="/">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<script>

var i=0;

function mm() {

i+=1;

document.data.srno.innerHTML=""+i;

}

</script> 
<meta http-equiv="Content-Type" 

content="text/html; charset=iso-8859-1"/>

<title>Sample XSL Example [Sorting]</title>

<style type="text/css">

<xsl:comment>

.style3 {font-family: 

Geneva, Arial, Helvetica, sans-serif; color: #0033FF; }

</xsl:comment>

</style>

</head>

<body>
<table width="59%" id="data" xsl:use-attribute-sets="table1">

  <tr>

    <td width="9%" nowrap="nowrap"

 bgcolor="#6699FF"><strong>Sr no </strong></td>

    <td width="22%" bgcolor="#6699FF">

<strong>EMP ID </strong></td>

	<td width="30%" bgcolor="#6699FF"

><strong>Name</strong></td>
    
    <td width="20%" bgcolor="#6699FF">

<strong>Age</strong></td>

    <td width="20%" bgcolor="#6699FF">

<strong>Department</strong></td>
   
    <td width="19%" bgcolor="#6699FF">

<strong>Designation</strong></td>

	<td width="19%" nowrap="nowrap" bgcolor="#6699FF">

<strong>Phone No </strong></td>

	<td width="19%" nowrap="nowrap" bgcolor="#6699FF"

><strong>Address </strong></td>

  </tr>
<xsl:for-each select="ebiz/employee_details">

<xsl:sort data-type="number" order="ascending" select="age" />
	<tr>

    <td><span class="style3">.

      <script>i=i+1;document.write(i);</script>
</span></td>

     <td nowrap="nowrap"><span class="style3">

<xsl:value-of select="emp_id" /></span></td>

	 <td nowrap="nowrap"><span class="style3"><

xsl:value-of select="fname"> </xsl:value-of>

    <xsl:value-of select="lname"></xsl:value-of></span></td>
   
     <td nowrap="nowrap" class="style3">

<xsl:value-of select="age" /></td>

     <td nowrap="nowrap">

<xsl:value-of select="department" /></td>
    
    <td nowrap="nowrap">

<xsl:value-of select="designation" /></td>

	<td nowrap="nowrap"> 

 <xsl:value-of select="phone" /></td	>

	<td nowrap="nowrap"><
xsl:value-of select="address"/></td>

  </tr></xsl:for-each>

</table>
 
</body>

</html>

</xsl:template>

</xsl:stylesheet>
Click here to view the XSL file, XML file without formatting and formatted XML file
Numbering
<xsl:number

  count="pattern"

  format="{ string }"

  from="pattern"

  grouping-separator="{ character }"

  grouping-size="{ number }"

  lang="{ languagecode }"

  letter-value={ "alphabetic" | "traditional" }

  level="any" | "multiple" | "single"

  value="expression"
>
</xsl:number>
The xsl:number element has two possible uses. It can determine the sequence number for the current node and it can format a number for display in the output.
The sequence number is the integer position of the current node in a source document (source tree). There are actually three ways that the sequence number can be determined and you can use the level attribute to choose which way.
The formatting process converts either the sequence number or the number provided by the value attribute to a string. By using various attributes of the xsl:number element, you can exert great control over the appearance of the formatted number in the output.
In comparison, the xsl:decimal-format element defines the symbols and characters used by the format-number function to convert numbers to strings.
This is a self-closing element and it cannot contain any child elements or any content.

count="pattern"
The optional count attribute dictates what nodes are to be counted. Only nodes that match the pattern are counted. The default is to count any node that matches the pattern of the current node.

format="{ string }"
The optional format attribute is set to an Attribute Value Template that dictates the output format for the number. You can use any the following choices:
FormatOutput Sequence
11 2 3 4 ... 10 11 12 ...
0101 02 03 04 ... 10 11 12 ...
aa b c ... z aa ab ac ...
AA B C ... Z AA AB AC ...
ii ii iii iv v vi vii viii ix x ...
II II II IV V VI VII VIII IX X ...
For example, format="1.A.a. " would allow the appropriate paragraph to be numbered 6.C.b.
from="pattern"
The optional from attribute specifies a starting point from which the sequential counting will start. The nodes are matched to the pattern to find the starting point. grouping-

separator="{ character }"
The optional grouping-separator attribute is set to an Attribute Value Template or a character that dictates what character is to be used to separate groups of digits in the number being displayed in the output. White-space is permitted. The grouping-separator attribute is ignored if you do not also set the grouping-size attribute to the digit group size. The classic example is to use a comma to separate groups of three digits.
grouping-size="{ number }"
The optional grouping-size attribute is set to an Attribute Value Template or a number that dictates how many digits are in the groups that are being separated by the character specified in the grouping-separator attribute. The grouping-size attribute is ignored if you do not also use the grouping-separator attribute to specify a separator. The classic example are groups of three digits separated by a comma.

lang="{ languagecode }"
The optional lang attribute is set to an Attribute Value Template or a string that dictates the language code which in turn specifies the language alphabet to be used for the numbering. The default language is set by the operating system environment.

letter-value="{ alphabetic | traditional }"
The optional letter-value attribute is set to an Attribute Value Template that dictates whether the numbering sequence in the selected language is either alphabetic or traditional. Or it can be set directly to either one of the two permitted values. The primary example is Traditional Hebrew versus Alphabetic Hebrew. The default is alphabetic

level="any" | "multiple" | "single"
The optional level attribute is set to an Attribute Value Template that controls how the sequence number is assigned. Or it can be set directly to one of the three permitted values. There are only three permitted procedures for determining a sequence number:
LevelEffect
singleThe default value. All preceding nodes that match the target node pattern are counted. Limitations imposed by the from and count attributes are obeyed. The sequence starts at one. If the current target node has four preceding nodes, then the current target node will be given the sequence number of five.
multipleFirst, a list is constructed of all ancestors of the current node. The list goes back to, but does not include, the ancestor that matches the optional fromattribute pattern. Next, for each node in the list that matches the countpattern, the XSL processor maps how many preceding siblings of that node match the count pattern. This hierarchic position information is provided in a composite sequence number list.
anyStarting from the current node, the XSL processor counts how many nodes match the count attribute pattern. If a node specified in the optional fromattribute is encountered, the counting process stops. The sequence number is the number of nodes counted. This can be zero, if the current node does not match the count pattern.
value="expression"
The optional value attribute is a user-provided number that is used in place of a sequence generated number. If the expression generates a real number, it will be rounded and converted to an integer. The default is to use a sequence number which is based upon the current node's position in the source document (source tree).
<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE xsl:stylesheet  [

	<!ENTITY nbsp   " ">

	<!ENTITY copy   "©">

	<!ENTITY reg    "®">

	<!ENTITY trade  "™">

	<!ENTITY mdash  "—">

	<!ENTITY ldquo  "“">

	<!ENTITY rdquo  "”"> 

	<!ENTITY pound  "£">

	<!ENTITY yen    "¥">

	<!ENTITY euro   "€">
]>
<xsl:stylesheet version="1.0" xmlns:

xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="phone address" />

<xsl:preserve-space elements="fname" />

<xsl:output method="html" encoding="iso-8859-1" 

doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 

doctype-system="http://www.w3.org/

TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:attribute-set name="table1" >

<xsl:attribute name="border">
2
</xsl:attribute>
<xsl:attribute name="bgcolor">

"#9999FF"

</xsl:attribute>

<xsl:attribute name="border">
1
</xsl:attribute>
<xsl:attribute name="cellpadding">
3
</xsl:attribute>

<xsl:attribute name="cellspacing">
1
</xsl:attribute>
</xsl:attribute-set>

<xsl:template match="/">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" 

content="text/html; charset=iso-8859-1"/>

<title>Sample XSL Example [Sorting]</title>

<style type="text/css">

<xsl:comment>

.style3 {font-family: Geneva, 

Arial, Helvetica, sans-serif; color: #0033FF; }

</xsl:comment>
</style>
</head>

<body>

	

<table width="59%" id="data" xsl:use-attribute-sets="table1">

  <tr>
    <td width="9%" nowrap="nowrap" 

bgcolor="#6699FF"><strong>Sr no </strong></td>

    <td width="22%" bgcolor=

"#6699FF"><strong>EMP ID </strong></td>

	<td width="30%" bgcolor=

"#6699FF"><strong>Name</strong></td>
    
    <td width="20%" bgcolor="#6699FF">

<strong>Age</strong></td>

    <td width="20%" bgcolor="#6699FF">

<strong>Department</strong></td>

   
    <td width="19%" bgcolor="#6699FF">

<strong>Designation</strong></td>

	<td width="19%" nowrap="nowrap"

 bgcolor="#6699FF"><strong>Phone No </strong></td>

	<td width="19%" nowrap="nowrap

" bgcolor="#6699FF"><strong>Address </strong></td>

  </tr>
<xsl:for-each select="ebiz/employee_details">

<xsl:sort data-type="number" order="ascending" select="age" />
	<tr>
<td><xsl:number value="position()" format="A. " /></td>

    <xsl:comment>Notice the 

script that was used earlier to 

generate serial number has been removed</xsl:comment>

     <td nowrap="nowrap"><span class="style3">

<xsl:value-of select="emp_id" /></span></td>

	 <td nowrap="nowrap"><span class="style3"

><xsl:value-of select="fname"> </xsl:value-of> 

   <xsl:value-of select="lname"></xsl:value-of></span></td>
   
     <td nowrap="nowrap" class="style3">

<xsl:value-of select="age" /></td>

     <td nowrap="nowrap"><xsl:value-of 

select="department" /></td>
    
    <td nowrap="nowrap"><xsl:value-of 

select="designation" /></td>

	<td nowrap="nowrap"> 

 <xsl:value-of select="phone" /></td	>

	<td nowrap="nowrap">

<xsl:value-of select="address"/></td>

  </tr></xsl:for-each>
</table>
 
</body>

</html>

</xsl:template>

</xsl:stylesheet>
Click here to view the above XSL file and eBIZ.com staff List with this XSL.
XSL:Number Example    by http://education.ebizel.com

XSL Elements Index
XSLT Element Index
XML is one of the most important of all recent innovations to hit the web. The XML technology provides a means of storing data in a structured manner. If you are not familiar with XML, then I recommend you to first read our XML tutorial athttp://education.ebizelindia.com
AIP
xsl:apply-importsxsl:ifxsl:preserve-space
xsl:apply-templatesxsl:importxsl:processing-instruction
xsl:attributexsl:includexsl:param
xsl:attribute-setxsl:keyxsl:pi
Q
BJR
CKS
xsl:call-templatexsl:script (msxsl:script)
xsl:cdataxsl:sort
xsl:choosexsl:strip-space
xsl:comment
L
xsl:stylesheet
xsl:copy
xsl:copy-of
DMT
xsl:decimal-formatxsl:messagexsl:template
xsl:define-template-set
xsl:text
xsl:transform
ENU
xsl:elementxsl:namespace-alias
xsl:entity-refxsl:node-name
xsl:evalxsl:number
FOV
xsl:fallbackxsl:otherwisexsl:value-of
xsl:output
xsl:variable
xsl:for-each
W
xsl:when
Gxsl:with-param
X
Y
HZ

XSL Elements Index
XPath Functions
Note that these function names are used as is, without a prefix. (Some companies offer proprietary XPath functions that usually require a prefixed name.)
boolean
The Boolean function converts the value argument to a Boolean and returns a true or false. Sloppy
Syntax: true | false = boolean(value)
ceiling 

The ceiling function returns the smallest integer that is equal to or is larger than the numeric value of the number argument.

Syntax: number = ceiling(number)
concat

The concat function takes all of the individual arguments, concatenates them together in order, and returns the resultant string. 

Syntax: string = concat(value1, value2, ...)
contains

The contains function determines if the substring argument is contained within the value argument and, if yes, returns a true. If no, a false is returned. 

Syntax: true | false = contains(value, substring)
count
The count function counts and returns the number of nodes in a node-set.

Syntax: number = count(node-set)
false 

The false function return the Boolean value of false. There are no arguments. 


Syntax: false = false()
floor 

The floor function returns the largest integer that is equal to or is smaller than the numeric value of the number argument.

Syntax: number = floor(number)
id

The id function returns a node-set containing zero or more nodes that have an attribute that match the value argument. 

Syntax: node-set = id(value)
lang 

The lang function tests whether the language specified by the language argument matches the language of the context node (which is normally assigned by the xsl:langelement). If yes, true is returned. If no, or if no language is assigned to the context node, false is returned.

Syntax: true | false = lang(language)
last 
The last function returns the position number assigned to the last node in the current node list that is being processed by an xsl:for-each or xsl:apply-templates element. There are no arguments.
Syntax: number = last()
local-name 

The local-name function returns the local part of a qname (or an empty string if there is no local name). A qname is composed of an optional prefix, a colon that must be present if there is a prefix, followed by the local name. The local name is dependent on node type. The node argument is optional. If omitted, the default is to use the context node.

Syntax: string = local-name(node)
name 

The name function returns the qname of the node. A qname is composed of an optional prefix, a colon that must be present if there is a prefix, followed by the local name. The node argument is optional. If omitted, the default is to use the context node.
Syntax: string = name(node)
namespace-uri 

The namespace-uri function returns a string that is the namespace URI of the node cited in the optional node argument. If the argument is omitted, the default is to find the namespace URI of the context node.

Syntax: uri = namespace-uri(node)
normalize-space
The normalize-space function returns a string in which all of the preceding and trailing white space has been removed, and in which all internal sequences of white is replaced with one white space. The string argument is optional. If omitted, the default is to use the string value of the context node.

Syntax: string = normalize-space(string)
not

The not function returns the Boolean negation of the condition argument (true becomes false and vice-versa).

Syntax: true | false = not(condition)
number 

The number function converts the value argument to a number. The value argument is optional. If omitted, the default is to use the string value of the context node.

Syntax: number = number(value)
position 

The position function returns the position number in the current node list of the node that is currently being processed by an xsl:for-each or xsl:apply-templates element. There are no arguments.

Syntax: number = position()
round 

The round function rounds a number to its closest integer.

Syntax: integer = round(number)
starts-with

The starts-with function tests whether the string specified in the string argument starts with the substring specified in the substring argument. If yes, true is returned. If no, a false is returned.

Syntax: true | false = starts-with(string, substring)
string 

The string function converts the value argument to a string. The value argument is optional. If omitted, the default is to use the string value of the context node.

Syntax: = string()
string-length 

The string-length function returns the number of characters in a string. The string argument is optional. If omitted, the default is to use the string value of the context node.

Syntax: number = string-length(string)
substring 

The substring function returns a portion out of the string specified in the string argument as determined by the starting point specified in the start argument and also by the optional length specified in the length argument.

Syntax: string = substring(string, start, length)
substring-after 

The substring-after function returns a portion out of the string specified in the string argument that occurs after the substring specified in the substring argument.
Syntax: string = substring-after(string, substring)
substring-before

The substring-before function returns a portion out of the string specified in the string argument that occurs before the substring specified in the substring argument.

Syntax: string = substring-before(string, substring)
sum 

The sum function adds and returns the total value of a set of numeric values that are contained in a node-set.

Syntax: number = sum(node-set)
translate 

The translate function takes the string in the value argument, replaces all occurrences of a string specified in the string1 argument with substitute characters specified in string2 argument and returns the modified string.

Syntax: string = translate(value, string1, string2) true
The true function returns the Boolean value of true. There are no arguments.
Syntax: = true()

XSL Elements Index
XSLT Functions
XSLT includes over 100 built-in functions. There are functions for string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values, and more.
Note: XQuery 1.0, XPath 2.0, and XSLT 2.0 share the same functions library.
The following XSLT and XPath functions should return true if a processor supports theW3C XSLT standard.
booleanname
ceilingnamespace-uri
concatnormalize-space
containsnot
countnumber
currentposition
documentround
element-availablestarts-with
falsestring
floorstring-length
format-numbersubstring
function-availablesubstring-after
generate-idsubstring-before
idsum
keysystem-property
langtranslate
lasttrue
local-nameunparsed-entity-uri
XSLT extends the set of available functions with these:
node-set document(object, node-set?)
Allows XSLT to access the nodes in another document
node-set key(keyname, object) 

Returns the nodes that match object in the specified key
string format-number(number, formatstring, [decimalformat]) 

Returns the string representation of number using the formatstring specified and the decimalformat (or the default decimal format)
node-set current() 

Returns the current context node
string unparsed-entity-uri(string) 

Returns the URI of the specified unparsed entity
string generate-id(node-set)

Returns a string which uniquely identifies the specified node, or the first node in document order
object system-property(string)

Returns the value of the specified system property
boolean element-available(string) 

Returns true if the specified element is available in the implementation
boolean function-available(string)
Returns true if the specified function is available in the implementation function-name
The function-name argument is simply the qname of the function that you wish to test. A qname is an XML name with an optional prefix. If the value is not of type string, it will automatically be converted to a string by the XPath string() function.
Boolean = function-available(function-name) 

The function-available function is used to test whether the function specified in the argument is supported by the XSLT processor. Currently, this is important when dealing with proprietary functions. In the future, this function will gain additional importance when you have to content with more than one version of the W3C XSLT standard.

If the function is supported, true is returned. If the function is not supported, false is returned.

XSL Elements Index
<xsl:stylesheet> or <xsl:transform>
The <xsl:stylesheet> or <xsl:transform> elements identify a complete stylesheet. They are completely synonymous.
<xsl:stylesheet id = id
extension-element-prefixes = tokens
exclude-result-prefixes = tokens version = number>
<!-- Content: (xsl:import*, top-level-elements) -->
</xsl:stylesheet>
id 
A unique identifier
extension-element-prefixes

Identifies namespace (http://www.w3.org/TR/REC-xml-names) prefixes that are extension element prefixes
exclude-result-prefixes 

Lists namespace (http://www.w3.org/TR/REC-xml-names) prefixes that should not be put in the result tree
version 

The XSLT version to which this stylesheet conforms (required)

XSL Elements Index
<xsl:template>
<xsl:template match="pattern"

mode="qname"

name="qname"

priority="number" >

</xsl:template>
The xsl:template element is used to define a template that can be applied to a node to produce a desired output display. There must be either a match or name attribute, or both, and this determines how the template rule can be invoked.
If there is only a match attribute, then you can use the xsl:apply-template element to invoke the template rule defined by the xsl:template element. If there is only a name attribute, then you can use the xsl:call-template element to invoke the named template defined by the xsl:template element. If both attributes are present, then you may invoke the template by either procedure.
It is quite possible that more than one template can be applied to a node. The highest priority value template is always chosen. If more than one suitable template has the same highest priority value, then the XSLT processor usually chooses the one that appears last. Different templates can not have both the same name and priority values. This is an error.
The xsl:template element is always a child of either the xsl:stylesheet or xsl:transform elements.
This is not a self-closing element. The separate closing element is mandatory

match="pattern"
The match attribute is mandatory unless the element has a name attribute, then this attribute is optional. In other words, there must be either a match or name attribute, or both. This attribute is a pattern that is used to define which nodes will have which template rules applied to them.

mode="qname"
The optional mode attribute allows the same nodes to be processed more than once. Each time the nodes are processed, they can be displayed in a different manner.
A qname is a qualified name that is composed of an optional namespace prefix, a colon, which is only present if there is a prefix, and a mandatory XML name (for example,xsl:zipcode or zipcode). If an xsl:template element has a mode attribute, then it must also have a match attribute.
If the xsl:apply-templates element has a mode attribute, then it can only apply templates from xsl:templates elements that also have a mode attribute. Likewise, if the xsl:apply-templates element does not have a mode attribute, then it can only apply templates from xsl:templates elements that also do not have a mode attribute.
name="qname"
The name attribute is mandatory unless the element has a match attribute, then this attribute is optional. In other words, there must be either a match or name attribute, or both. A qname is a qualified name that is composed of an optional namespace prefix, a colon which is only present if there is a prefix, and a mandatory XML name (for example, xsl:zipcode or zipcode).
If the name attribute is present, you can use the xsl:call-template element to invoke the template. To do this, the name attribute must be the same for both the xsl:template and the xsl:call-template elements.
priority="number"
The optional priority attribute is a real number that ranges from -9.0 to 0.0 to 9.0 that sets the priority of importance for a template. The higher the number, the higher the priority. If more than one template is suitable for a node, then the highest priority template is always chosen.
The most common default value is 0 (zero), however the exact default value that will be assigned by the XSLT processor is dependent on the pattern information contained in the match attribute.

XSL Elements Index
<xsl:apply-templates>
<xsl:apply-templates
select="expression"
mode="qname" >
</xsl:apply-templates>
The xsl:apply-templates element defines a set of nodes to be processed, or by default selects all child nodes of the current node being processed, and finds a matching template rule to apply to each node in the set.
Since each node in the node set is treated individually, it is possible for each node to have a different template applied to it. Note that a template rule is not actually returned, but rather, it manifests itself by how the node is displayed in the output.
There are only two possible procedures by which a template rule can be chosen for a node. If the node matches the pattern defined by the match attribute of anxsl:template element, then that template will be applied.
If more that one such match occurs, then the template with the highest priority will be applied. Or if the priorities are the same, the last template encountered with that priority will be applied. If there are no templates, or a match cannot be found, then the XSLTprocessor will apply a built-in template rule.
The xsl:apply-templates element can only contain the xsl:sort or xsl:with-paramelements. By default the nodes will be assigned templates in the order that they occur. However, if there are one or more xsl:sort instructions, then the nodes will be sorted before the templates are assigned.
The actual assignment of a template to a specific individual node is not dependent on the sorting order. The xsl:with-param element defines parameters that will be applied to the template rules.
This is not a self-closing element. The separate closing element is mandatory.
mode="qname"
The optional mode attribute allows the same nodes to be processed more than once. Each time the nodes are processed, they can be displayed in a different manner. A qname is a qualified name that is composed of an optional namespace prefix, a colon which is only present if there is a prefix, and a mandatory XML name (for example,xsl:zipcode or zipcode).
If an xsl:apply-templates element has a mode attribute, then it can only apply template rules from xsl:template elements that also have a mode attribute.
select="expression"
The optional select attribute is set to an expression that returns a node set. This can simply be a string that is the name of a node set.
The nodes in the node set are processed in the order that they occur (which is called document order). The default for omitting this attribute is to select all of the child nodes of the current node being processed.

XSL Elements Index
<xsl:for-each>
<xsl:for-each select="expression" />
</xsl:for-each>
The xsl:for-each element loops through each node in a node set in itsr order of occurrence and applies the same template to each node. A node set is simply the collection of all of the same XML tags (nodes) in an XML file. This process is also referred to as iterating over a set of nodes. The template is contained inside thexsl:for-each element between the opening and closing element. The syntax is:
<xsl:for-each> code ... </xsl:for-each>
In a formal definition, the template is said to be instantiated once to each node in the node set. The default is to iterate through the nodes in the order in which they occur. This is referred to as document order. However, you may prefer to rearrange the order by using the xsl:sort element. This element defines the sort key upon which the sort (reorder) will be based.
This element is not self-closing. The separate closing element is mandatory.
select="expression"
The mandatory select attribute provides an expression that specifies which node set is to be processed by the loop. This can simply be a string that is the name of the node. Only one node set can be defined. However, by selecting a parent node, you can access the values of any child node via the template.
You can use the position function to return the position number of the node currently being processed (the numbering starts at one). You can use the last function to return the total number of nodes being processed.
Example:
<xsl:stylesheet version="1.0" xmlns:xsl=

"http://www.w3.org/1999/XSL/Transform">

<xsl:strip-space elements="phone address" />

<xsl:preserve-space elements="fname" />

<xsl:output method="html" encoding="iso-8859-1" 

doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 

doctype-system="http://www.w3.org/TR/

xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:attribute-set name="table1" >

<xsl:attribute name="border">
2
</xsl:attribute>
 
<xsl:attribute name="bgcolor">

"#9999FF"
</xsl:attribute>

<xsl:attribute name="border">

1
</xsl:attribute>

<xsl:attribute name="cellpadding">

3
</xsl:attribute>

<xsl:attribute name="cellspacing">

1
</xsl:attribute>

</xsl:attribute-set>


<xsl:template match="/">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content=

"text/html; charset=iso-8859-1"/>

<title>Sample XSL Example []</title>

<style type="text/css">
<xsl:comment>

.style3 {font-family: Geneva, Arial,

 Helvetica, sans-serif; color: #0033FF; 

</xsl:comment>

</style>

</head>

<body>
<table width="59%" id="data" xsl:use-attribute-sets="table1">

  <tr>
    <td width="9%" nowrap="nowrap" bgcolor="#6699FF">

<strong>Sr no </strong></td>

    <td width="22%" bgcolor="#6699FF"><strong>

EMP ID </strong></td>

	<td width="30%" bgcolor="#6699FF"><strong

>Name</strong></td>
    
    <td width="20%" bgcolor="#6699FF"><strong>

Age</strong></td>

    <td width="20%" bgcolor="#6699FF"><strong>

Department</strong></td>

   
    <td width="19%" bgcolor="#6699FF"><strong>

Designation</strong></td>

	<td width="19%" nowrap="nowrap" bgcolor="#6699FF">

<strong>Phone No </strong></td>

	<td width="19%" nowrap="nowrap" bgcolor="#6699FF"><

strong>Address </strong></td>

  </tr>
<xsl:for-each select="ebiz/employee_details">

<xsl:sort data-type="number" order="ascending" select="age" />
	<tr>
<td><xsl:number value="position()" format="A. " /></td>

    <xsl:comment>Notice the script that was used 

earlier to generate serial number has been removed</xsl:comment>

     <td nowrap="nowrap"><span class="style3">

<xsl:value-of select="emp_id" /></span></td>

	 <td nowrap="nowrap"><span class="style3"><

xsl:value-of select="fname"> </xsl:value-of>    

<xsl:value-of select="lname">
</xsl:value-of></span></td>
   
     <td nowrap="nowrap" 
class="style3"><xsl:value-of select="age" /></td>

     <td nowrap="nowrap">
<xsl:value-of select="department" /></td>

    
    <td nowrap="nowrap">

<xsl:value-of select="designation" /></td>

	<td nowrap="nowrap"> 

 <xsl:value-of select="phone" /></td	>

	<td nowrap="nowrap"><xsl:value-of select="address"/></td>

  </tr>

  </xsl:for-each>

</table>
 
</body>

</html>

</xsl:template>

</xsl:stylesheet>


XSL Elements Index
<xsl:call-template>
<xsl:call-template name="qname" > </xsl:call-template>
The xsl:call-template element is used to invoke a template by name. By invoke, we mean that the named template is called and applied to the source document. If a template does not have a name, it cannot be called by this element.
The xsl:template element is used to create a template. You can name a template by using the name attribute of the xsl:template element. Further, the name called by the mandatory name attribute of the xsl:call-template element must match the name specified by the name attribute of the xsl:template element. Complicating matters is the fact that a template is not required to have a name.
A template is only required to have either a name or match attribute. (It can have both.) Ideally, each template will have a unique name. However, if a name is repeated, then the two templates must have a different import precedence (refer to thexsl:import element), otherwise it is an error.
An xsl:call-template element cannot directly return a result. You need to enclose thexsl:call-template element inside an xsl:variable element which serves as the current output destination (see code example).
The xsl:call-template element can contain zero or more xsl:with-param elements. It cannot contain any other XSLT elements. These xsl:with-param elements will only be evaluated if there is a matching xsl:param element in the template being called. If there is no such match, then the xsl:with-param element is simply ignored.
This is not a self-closing element. The separate closing element is mandatory.
name="qname"
The mandatory name attribute is the unique qname of the template that you wish to invoke. A qname is a qualified name that is composed of an optional namespace prefix, a colon which is only present if there is a prefix, and a mandatory XML name (for example, xsl:zipcode or zipcode).
This name must match the name used by the name attribute of the xsl:templateelement that was used originally to create the template.
Source code for eBIZ staff xml file:
<?xml version="1.0" encoding="iso-8859-1"?>
 
     <ebiz>

		<employee_details>

			<emp_id>eBIZTECH001</emp_id>

			<fname>Mr Aman Kumar</fname>

			<lname>Singh</lname>

			<department>TECHICAL[Java]</department>

			<designation>Sr. Developer</designation>

			<phone> 32942</phone>

			<address>Sector 44, Noida</address>

			<age>27</age>

		</employee_details>

		<employee_details>
			<emp_id>eBIZCSS001</emp_id>

			<fname>Mrs Sunita</fname>

			<lname>Singhania</lname>

			<department>Customer S

upport[Web Assist]</department>
<designation>CCE</designation>

			<phone> 000000</phone>

			<address>Sector 66, Gurgaon</address>

			<age>20</age>

		</employee_details>


		<employee_details>
			<emp_id>eBIZAC001</emp_id>

			<fname>Miss Amisha</fname>

			<lname>Mishra</lname>

			<department>Accounts</department>

			<designation>Jr. Accountant</designation>

			<phone> 32942</phone>

			<address>Sector 66, Rohni</address>

			<age>26</age>

		</employee_details>

		<employee_details>

			<emp_id>eBIZAC002</emp_id>

			<fname>ANITA</fname>

			<lname>Mishra</lname>

			<department>Accounts</department>

			<designation>Jr. Accountant</designation>

			<phone> 09999 </phone>

			<address>Sector 66, Noida</address>

			<age>23</age>

		</employee_details>
<employee_details>

			<emp_id>eBIZAC003</emp_id>

			<fname>ANKITA</fname>

			<lname>DUBEY</lname>

			<department>Accounts</department>

			<designation>Jr. Accountant</designation>

			<phone>032942 </phone>

			<address>Sector 99, Noida</address>

			<age>21</age>

		</employee_details>

		<employee_details>

			<emp_id>eBIZAC004</emp_id>

			<fname>AKSHITA</fname>

			<lname>Jaiswal </lname>

			<department>TECHICAL[Java]</department>

			<designation>Jr. DEVELOPER</designation>

			<phone> (+91)99990</phone>
Source code for xslt_call_template.xsl:
<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE xsl:stylesheet  [
	<!ENTITY nbsp   " ">

	<!ENTITY copy   "©">

	<!ENTITY reg    "®">

	<!ENTITY trade  "™">

	<!ENTITY mdash  "—">

	<!ENTITY ldquo  "“">

	<!ENTITY rdquo  "”"> 

	<!ENTITY pound  "£">

	<!ENTITY yen    "¥">

	<!ENTITY euro   "€">

]>
<xsl:stylesheet version="1.0" xmlns:xsl=

"http://www.w3.org/1999/XSL/Transform">

<xsl:template name="main" match="/">

  <html>

  <body>

  <xsl:for-each select="ebiz/employee_details">
  
<xsl:sort data-type="number" order="ascending" select="age" />

<span style="width:400px;background-color: 

#3344FF; border: solid 2px inset blue">

    <xsl:call-template name="data">

      <xsl:with-param name="ename" select="fname" />

      <xsl:with-param name="edob" select="age" />

    </xsl:call-template> </span>

  </xsl:for-each>
 
  </body>

  </html>
</xsl:template>

<xsl:template name="data">

  <xsl:param name="ename" select="'Not Available'" />

  <xsl:param name="edob" select="'Not Available'" />
  <div>

  NAME: <xsl:value-of select="$ename" />

  <br />

  DOB: <xsl:value-of select="$edob" />

  <hr />

  </div>

</xsl:template>

</xsl:stylesheet>
Output: Try it yourself.

0 comments: