Images

XSL - PART II


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.



Style Sheets
Applying Style
One model for applying style is to allow the process to run recursively, driven primarily by the document. A series of templates is created, such that there is a template to match each context, then these templates are recursively applied starting at the root of the document.

<xsl:template>
<xsl:template match="section/title">
<h2><xsl:apply-templates/></h2>
</xsl:template>

<xsl:apply-templates>
<xsl:apply-templates select="th|td"/>
There are two obstacles to overcome when using the recursive model, how to arbitrate between multiple patterns that match and how to process the same nodes in different contexts.
<xsl:stylesheet
version="version_number"
id="unique_id"
exclude-result-prefixes="list"
extension-element-prefixes="list" >
</xsl:stylesheet>
The xsl:stylesheet element contains all other XSLT elements and delimits the start and stop of the code in an .xsl program. No other XSLT element can occur before the opening xsl:stylesheet element, nor may any other XSLT element occur after the closing xsl:stylesheet element.
A direct comparison can be made between the opening and closing <html> ... </html> tags of the HTML language, in that both the html tag and the xsl:stylesheet element serve as delimiting containers for all other members of their respective languages.
An important duty performed by the xsl:stylesheet element is that it must contain theXSLT namespace declaration. The purpose of the namespace declaration is to declare that the document is an XSLT stylesheet. Use the following syntax:
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

Older, proprietary versions of Microsoft XSLT used the following namespace: 

xmlns:xsl="http://www.w3.org/TR/WD-xsl"
The xsl:stylesheet element is also commonly referred to as the root element of the stylesheet. Since it is the root, there can be no other element that is a parent to the xsl:stylesheet element. All other XSLT elements are either children, grandchildren, or further descendants. Only the following eight XSLT elements can be children:
• xsl:attribute-set
• xsl:import
• xsl:include
• xsl:output
• xsl:param
• xsl:script
• xsl:template
• xsl:variable
The xsl:transform element performs the exact same purpose as the xsl:stylesheet element. These two elements may be used interchangeably. They are considered synonymous with each other.
This is not a self-closing element. The separate closing element is mandatory
version="version_number"
The mandatory version attribute is set to the version number. Currently, the version number is "1.0".
id="unique_id"
The optional id attribute is a unique identifier for the stylesheet. This allows the stylesheet to be referenced in another XML document.
exclude-result-prefixes="list"
The optional exclude-result-prefixes attribute is a list, delimited by white-space, of the namespaces prefixes that should not be copied into the output (the result tree).
extension-element-prefixes="list"
The optional extension-element-prefixes attribute is a list, delimited by white-space, of the namespaces prefixes used for extension elements.
Consider the following example:
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- DWXMLSource="sample1.xml" -->
<!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:output method="html" encoding="iso-8859-1" 
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" 
doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
<xsl:template match="/">

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

<body>
<xsl:for-each select="ebiz/employee_details">
<div style="background-color:#009999; border:thin #000099 solid">
 <xsl:value-of select="emp_id"></xsl:value-of><br />
 <xsl:value-of select="lname"></xsl:value-of> 
 <span style="color:#000099"><xsl:value-of select="fname"><
/xsl:value-of></span><br />
 <xsl:value-of select="department"></xsl:value-of><br />
 <xsl:value-of select="designation"></xsl:value-of>

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

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

Style Sheets
Conflict Resolution
The problem of multiple patterns that match is handled by conflict resolution:
• Matching templates from imported modules are not considered if there is a matching template in the current module
• Matching templates with a lower priority are not considered. The default priority is determined as follows:
• Unqualified child or attribute names have a priority of 0.

• Processing-instructions with a target have a priority of 0.

• A namespace-qualified "*" child or attribute name has a priority of -0.25.

• An unqualified "*" has a priority of -0.5

• Any other template has a default priority of 0.5

• Template priority may be specified explicitly with the priority attribute on <xsl:template>

• "emphasis", "html:p", and "@foo" have a priority of 0

• "html:*" has a priority of -0.25

• "*" has a priority of -0.5

• "para/emphasis" has a priority of 0.5

• "emphasis/emphasis" has a priority of 0.5

• "emphasis[@role]" has a priority of 0.5
It is technically an error if the conflict resolution process yields more than one template, however, XSLT processors may (silently) recover from this error by selecting the template that occurs last in the stylesheet.
Effectively, this means that stylesheet template order is the final arbiter.

It is possible for a source node to match more than one template rule. The template rule to be used is determined as follows:
1. First, all matching template rules that have lower import precedence than the matching template rule or rules with the highest import precedence are eliminated from consideration.
2. Next, all matching template rules that have lower priority than the matching template rule or rules with the highest priority are eliminated from consideration. The priority of a template rule is specified by the priority attribute on the template rule. The value of this must be a real number (positive or negative), matching the production Number with an optional leading minus sign (-). [Definition: The default priority is computed as follows:]
o If the pattern contains multiple alternatives separated by |, then it is treated equivalently to a set of template rules, one for each alternative.

o If the pattern has the form of a QName preceded by a ChildOrAttributeAxisSpecifier or has the form processing-instruction(Literal) preceded by a ChildOrAttributeAxisSpecifier, then the priority is 0.

o If the pattern has the form NCName:* preceded by a ChildOrAttributeAxisSpecifier, then the priority is -0.25.

o Otherwise, if the pattern consists of just a NodeTest preceded by a ChildOrAttributeAxisSpecifier, then the priority is -0.5.

o Otherwise, the priority is 0.5.
Thus, the most common kind of pattern (a pattern that tests for a node with a particular type and a particular expanded-name) has priority 0. The next less specific kind of pattern (a pattern that tests for a node with a particular type and an expanded-name with a particular namespace URI) has priority -0.25.
Patterns less specific than this (patterns that just tests for nodes with particular types) have priority -0.5. Patterns more specific than the most common kind of pattern have priority 0.5.
It is an error if this leaves more than one matching template rule. An XSLT processor may signal the error; if it does not signal the error, it must recover by choosing, from amongst the matching template rules that are left, the one that occurs last in the stylesheet.

Style Sheets
Applying Style Procedurally
The other model for applying style is to select each action procedurally. A series of templates is created, such that each template explicitly selects and processes the necessary elements.
<xsl:for-each>
<xsl:for-each select="row">
<tr><xsl:apply-templates/></tr>
</xsl:for-each>
• Named Templates
<xsl:param>
<xsl:param name="type">warning</xsl:param>
<xsl:call-template>
<xsl:call-template name="admonition"/>
<xsl:with-param>
<xsl:call-template name="admonition">
<xsl:with-param name="type">caution</xsl:with-param>
</xsl:call-template>
For-each Example
foreach.xml
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="proc_style.xsl"?>
<table>
<row><entry>a1</entry><entry>a2</entry></row> <row><entry>b1</entry><entry>b2</entry></row> <row><entry>c1</entry><entry>c2</entry></row>
</table>
foreach.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE xsl:stylesheet[
 <!ENTITY nbsp " ">
 ]>
<xsl:stylesheet version="1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" />
<xsl:variable name="tbl">
  <tr>
  <td><b>Name</b></td>
  <td><b>Address</b></td>
  <td><b>Designation</b></td>
 </tr>
 </xsl:variable>
 <xsl:attribute-set name="tblAttrib">
 <xsl:attribute name="border">
 2
 </xsl:attribute>
 <xsl:attribute name="cellspacing">
 3
 </xsl:attribute>
 <xsl:attribute name="bordercolor">
"#3344dd"
 </xsl:attribute>
 </xsl:attribute-set><xsl:template match="table">
<ebizml>
<head>
<title>XSLT xsl:element Example</title>
</head> 

<body>
<span style="width 600px;border: 
2px outset blue solidl;display:block">

 
</span><br />
  <table cellspacing="0" border="1"
 bordercolor="blue" width="200">
    <xsl:for-each select="row">
      <tr>
        <xsl:for-each select="entry">
          <td><xsl:apply-templates/></td>
        </xsl:for-each>
      </tr>
    </xsl:for-each>
  </table>
  </body>

</ebizml>

</xsl:template>



 </xsl:stylesheet>
Click here to view the output

Style Sheets
Named Template Example
namedtemplate.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="named_temp_example.xsl"?>
<chapter>

<warning>
<para>Using a damaged extension cord may cause a fire.</para>
</warning>

<caution>
<para>Freshly brewed coffee is hot.</para>
</caution>
</chapter>
namedtemplate.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" />

<xsl:template name="admonition">
  <xsl:param name="type">Warning</xsl:param>
  <table border="1">
    <tr><th><xsl:value-of select="$type"/>:</th></tr>
    <tr><td><xsl:apply-templates/></td></tr>
  </table>
</xsl:template>

<xsl:template match="warning">
  <xsl:call-template name="admonition"/>
</xsl:template>


<xsl:template match="caution"><br />
  <xsl:call-template name="admonition">
    <xsl:with-param name="type">Caution</xsl:with-param>
  </xsl:call-template>
</xsl:template>

<xsl:template match="para">
  <p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="emphasis">
  <i><xsl:apply-templates/></i>
</xsl:template>
</xsl:stylesheet>
Click here to view the output

Style Sheets
Creating the Result Tree
Literal Result Elements
Any element in a template rule that is not in the XSL (or other extension) namespace is copied literally to the result tree
<xsl:text>
The content of <xsl:text> elements is copied directly to the result tree; whitespace is preserved by default

<xsl:text>Literal result text</xsl:text>
<xsl:value-of>
Inserts the value of an expression into the result tree, converting it to a string first if necessary

<xsl:value-of select="$count + 1"/>
<xsl:copy> and <xsl:copy-of>
Copies the current node or, in the case of xsl:copy-of, the selected nodes, into the result tree without first converting them to a string

<xsl:copy-of select="title"/>
<xsl:element>
Instantiates the named element
...
<xsl:param name="header">h3</xsl:param>
...
<xsl:element name="{$header}">
<xsl:apply-templates/>
</xsl:element>
<xsl:attribute>
Adds the named attribute to the nearest containing element
<table>
<xsl:if test="@pgwide='1'">
<xsl:attribute name="width">100%</xsl:attribute> </xsl:if>
...
</table>
Source code of xsl_result_tree.xsl:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE xsl:stylesheet[
 <!ENTITY nbsp " ">
 ]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" />
<xsl:variable name="tbl">
  <tr>
  <td><b>Name</b></td>
  <td><b>Address</b></td>
  <td><b>Designation</b></td>
 </tr>
 </xsl:variable>
 <xsl:attribute-set name="tblAttrib">
 <xsl:attribute name="border">
 2
 </xsl:attribute>
 <xsl:attribute name="cellspacing">
 3
 </xsl:attribute>
 <xsl:attribute name="bordercolor">
"#3344dd"
 </xsl:attribute>
 </xsl:attribute-set>
 
<xsl:template match="/">

<ebizml>
<head>
<title>XSLT xsl:element Example</title>
</head>
<body>
<span style="width 600px;border: 2px outset blue solidl;display:block">

 
</span><br />
<table xsl:use-attribute-sets="tblAttrib">
<xsl:copy-of select="$tbl" />
<xsl:for-each select="ebiz/employee_details">
 <tr>
 <td><xsl:element name="emp_name">
 <xsl:value-of select="fname" />  <xsl:value-of select="lname" />
 </xsl:element></td>
 <td><xsl:value-of select="address" /></td>
 <td><xsl:value-of select="designation" /></td>
</tr>

</xsl:for-each>
</table>
<br /> 
</body>
</ebizml>

</xsl:template>
</xsl:stylesheet>
Click here to view the output

Style Sheets
Conditional Processing
The xsl:if element evaluates an expression which returns a Boolean result to determine if a template should be instantiated. The evaluation is a simple True orFalse test on a defined condition or a set of conditions. If the test returns True, the template is applied and the results are displayed in the output. If False, the template is not applied (i.e., the contents between the opening and closing xsl:if are skipped over).
The actions of the xsl:if element are analogous to the if statement found in many other computer languages, such as in C and VBScript. However, there is no else statement. Therefore, if you need to choose from two or more possible courses of action, you may prefer to use the xsl:choose element.
One possible use of this element is to test for errors. The xsl:message element can be used to display error messages. This is not a self-closing element. The separate closing element is mandatory.
test="expression"
The mandatory test attribute is set to an expression that is a conditional test with either a True or False answer. The expression can contain more than one test condition by using the and, not, and or operators.
Consider the following XSL example that
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE xsl:stylesheet[
 <!ENTITY nbsp " ">
 ]>
<xsl:stylesheet version="1.0" xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" />
<xsl:variable name="tbl">
  <tr>
  <td><b>Name</b></td>
  <td><b>Address</b></td>
  <td><b>Designation</b></td>
 </tr>
 </xsl:variable>
 
<xsl:template match="/">

<ebizml>
<head>
<title>XSLT Conditional Processing</title>
</head>
<body>
<span style="width 600px;border: 2px 
outset blue solidl;display:block">

<xsl:text>eBIZ Employees List [25+ age]</xsl:text>
</span><br />
<table>
<xsl:copy-of select="$tbl" />
<xsl:for-each select="ebiz/employee_details">
<xsl:if test="age > 25">
<tr>
 <td><xsl:value-of select="fname" />  <
xsl:value-of select="lname" /></td>
 <td><xsl:value-of select="address" /></td>
 <td><xsl:value-of select="designation" /></td>
</tr></xsl:if>

</xsl:for-each>
</table>
<br />
<span style="width 600px;border:
 2px outset blue solidl;display:block">

<xsl:text>eBIZ Employees List [18-25 year older]</xsl:text>
</span><br />
<table xsl:use-attribute-sets="tblAttrib">
<xsl:copy-of select="$tbl" />
<xsl:for-each select="ebiz/employee_details">
<xsl:sort data-type="number" order="ascending" select="age" />
<xsl:if test="age <=25">
 <tr>
  <td><xsl:value-of select="fname" /> 
<xsl:value-of select="lname" /></td>
  <td><xsl:value-of select="address" /></td>
  <td><xsl:value-of select="designation" /></td>
 </tr>
</xsl:if>
</xsl:for-each>
</table>

</body>
</ebizml>

</xsl:template>
</xsl:stylesheet>
Source code of eBIZ_com_staff.xml :
<?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>TECHNICAL[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 Support[
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>
 </ebiz>
Click here to view the output

XSL Variables
Declaring and Using Variables
A variable in XSLT has more in common with a variable in algebra than with a variable in a typical programming language. It's a name that represents a value and, within a particular application of a template, it will never represent any other value -- it can't be reset using anything described in the XSLT Recommendation.
(Some XSLT processors offer a special extension function to allow the resetting of variables.)
XSLT variables actually have a lot more in common with constants in many programming languages and are used for a similar purpose. If you use the same value multiple times in your stylesheet, and there's a possibility that you'll have to change them all to a different value, it's better to assign that value to a variable and use references to the variable instead.
Then, if you need to change the value when re-using the stylesheet, you only change the value assigned in the creation of that variable.
The xsl:variable element is used to declare a local or global variable and to give that variable a name and a value. The value can be assigned by either the content of the xsl:variable element or by the select attribute, but not by both.
Each variable declaration requires a separate xsl:variable element. Global variables are declared in the top level of the style sheet (as children of the xsl:stylesheet or xsl:transform elements). Local variables are declared within the template body.
Note that once you set a variable's value, there is no provision in the XSLT language to change or modify that value. This is in sharp contrast to most other computer languages which allow you to repeatedly reassign variable values.
The xsl:param element can also be used to declare parameters. The only real difference between a variable and a parameter is how the value is assigned.
Like all XSLT elements, the xsl:variable element must be closed (well-formed). If the select attribute is present, then this element is self-closing. If the select attribute is not present, then this element is not self-closing and the separate closing element is mandatory.
Declaring Variables
<xsl:variable> allows you to associate a variable with a string, node list, or result tree fragment.
• Variables are "single assignment" (no side effects)

• Variables are lexically scoped

• Variables assigned inside a conditional only apply inside that conditional.
This is rarely correct:
<xsl:if test="$foo">

<xsl:variable name="bar">...</xsl:variable> </xsl:if>
Usually, you want to put the conditional inside the variable
<xsl:variable name="bar">
<xsl:if test="$foo">
...
</xsl:if>
</xsl:variable>
Using Variables
After variables (or parameters) have been declared, they can be used in two places:
• In XSL element attributes that expect an expression. These are summarized in the following table:
XSLT Element
Attribute
xsl:apply-templatesselect
xsl:value-ofselect
xsl:numbervalue
xsl:for-eachselect
xsl:iftest
xsl:whentest
xsl:sortselect
• In attribute value templates; attribute value templates have the form "{$variable}". They are allowed in the following places:
Element
Attribute
Literal result elementsany attribute
xsl:elementname
namespace
xsl:attributename
namespace
xsl:numberlevel
count
from
format
lang
grouping-separator
grouping-size
xsl:sortorder
lang
data-type
case-order
xsl:processing-instructionname
• To insert a literal "{" character in a context where attribute value templates are expanded, use "{{".
Source code for xsl_variable_example.xsl:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE xsl:stylesheet[
 <!ENTITY nbsp " ">
 ]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" />
<!-- XSL Variable Declaration-->
<xsl:variable name="tbl">
  <tr>
  <td><b>Name</b></td>
  <td><b>Address</b></td>
  <td><b>Department</b></td>
  <td><b>Designation</b></td>
  <td><b>Age</b></td>
  
  
 </tr>
 </xsl:variable>
 <xsl:template match="/">

<ebizml>
<head>
<title>XSLT xsl:choose Example</title>
</head>
<body>

<span style="width 600px;border: 2px outset blue solidl;display:block">


</span><br /> 
<table>
<xsl:copy-of select="$tbl" />
</table>
</body>
</ebizml>

</xsl:template>
</xsl:stylesheet>
Click here to view the example.

XSL Variables
Numbering
The <xsl:number> element performs two functions:

It evaluates a numeric expression and converts the result into a formatted string: <xsl:number value="3" format="A. "/><xsl:number value="count(listitem)" format="01"/> It counts elements in the source tree and converst the result into a formatted string:
<xsl:number count="listitem" format="i. "/>

<xsl:number count="chapter" from="book" level="any" format="1. "/>

<xsl:number count="h1|h2|h3" level="multiple" from="chapter|appendix" format="1."/>
The details of number to string conversion is spelled out in great detail in Section 7.7.1 (http://www.w3.org/TR/xslt.php#convert)oftheXSLTRecommendation (http://www.w3.org/TR/xslt.php).
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:numberelement, 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 }"
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.
Sorting
The <xsl:sort> element sorts a set of nodes according to the criteria specified:
<xsl:apply-templates select="row">
<xsl:sort data-type="number" select="entry[2]"/>
</xsl:apply-templates>
It can appear as a child of <xsl:apply-templates> or <xsl:for-each>. It can also be nested. 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"
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- DWXMLSource="sample1.xml" -->
<!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:output method="html" encoding="iso-8859-1" 
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
 doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
<xsl:template match="/">

<html>
<head>
<meta http-equiv="Content-Type" 
content="text/html; charset=iso-8859-1"/>
<title>XSL Sorting Example</title>
</head>

<body>
<xsl:for-each select="ebiz/employee_details">
<xsl:sort select="age" order="descending"/>
<div style="background-color:#009999; border:thin 
#000099 solid; width:80%">
 <xsl:value-of select="emp_id"></xsl:value-of><br />
 <xsl:value-of select="lname"></xsl:value-of> 
 <span style="color:#000099"><xsl:value-of select="fname"
></xsl:value-of></span><br />
 <xsl:value-of select="department"></xsl:value-of><br />
 <xsl:value-of select="designation"></xsl:value-of>

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

</xsl:template>
</xsl:stylesheet>
Click here to view the example.

0 comments: