| XSL Elements Index |
|
| <xsl:param> |
|
<xsl:param name="qname" >
</xsl:param>
Or:
<xsl:param name="qname" select="expression" /> |
|
| The xsl:param element is used to declare a local or global parameter and to give that parameter a name and a default value. The default value will be used only if no other value is provided when the template is called. |
|
| The default value can be assigned by either the content of the xsl:param element or by the select attribute, but not by both. Each parameter declaration requires a separate xsl:param element. |
|
| Global parameters are declared in the top level of the style sheet (as children of the xsl:stylesheet or xsl:transform elements). Local parameters are declared by using thexsl:param element as a child of the xsl:template element. |
|
| The actual (explicit) value is set by using xsl:with-param element when the template is applied (invoked) by either the xsl:apply-template or the xsl:call-templateelements. |
|
| The xsl:variable element can also be used to declare local and global variables. The only real difference between a variable and a parameter is how the value is assigned. |
|
| Like all XSLT elements, the xsl:param 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. |
|
| name="qname" |
|
| The mandatory name attribute is the qname of the expression. 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). |
|
| Note the following rules concerning when two different parameters can have the same name. (The same rules apply to the name attribute of the xsl:variable element.) |
|
| • A name can be repeated if one of the names is in an imported stylesheet and therefore has a lower import precedence. Under these circumstances, the higher import precedence name will always have precedence. |
|
| • Two different parameters can have the same name if they can never occur within the same scope. Therefore no ambiguity can occur (which would be an error). |
|
| • A local and global parameter can have the same name. However, when the local parameter is in scope, the global parameter cannot be accessed. |
|
| If the name attribute is assigned, a select attribute is not assigned, and there is no content, then the named parameter is set to be the empty string. |
|
| select="expression" |
|
| The optional select attribute is an expression that defines the parameter. If the select attribute is present, then the xsl:param element cannot contain any content and is self-closing. If an expression is given, the data type must be Boolean, node-set, number or string. |
|
| If it is a (literal) string, the string must be enclosed within opening and closing quotes and in turn, that default value must be enclosed again in opening and closing quotes. For example: |
|
<xsl:param name="car" select=" ' Ford ' " />
Or
<xsl:param name="car" select=' " Ford " ' /> |
|
| If the name attribute is assigned, a select attribute is not assigned, and there is no content, then the named parameter is set to be the empty string for the default value. |
|
| Here is the source code of xslt_call_template.xsl that uses xsl:parm element: |
|
<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" />
<xsl:call-template name="boo">
<xsl:with-param name="ename" select="fname" />
<xsl:with-param name="edob" select="age" />
</xsl:call-template>
</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="$myname" />
<br />
DOB: <xsl:value-of select="$mydob" />
<hr />
</div>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
| XSL Elements Index |
|
| <xsl:with-param> |
|
<xsl:with-param name="qname" >
</xsl:param>
Or:
<xsl:with-param name="qname" select="expression" /> |
|
| The xsl:with-param element is used to set the explicit value of a named parameter when using the xsl:apply-templates and the xsl:call-template elements. |
|
| The concept is that the xsl:param element is used to declare a local or global parameter by assigning a name and a default value. The xsl:with-param element is used to set the actual (explicit) value which will be used in place of the default value. |
|
| The name cited by the xsl:with-param element must match a name in an xsl:paramelement. If there is no such match, the xsl:with-param element is simply ignored, but it is not treated as an error. |
|
| Like all XSLT elements, the xsl:with-param 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. |
|
| name="qname" |
|
| The mandatory name attribute is the qname of the expression. 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). |
|
| Note the following rules concerning when two different parameters can have the same name. (The same rules apply to the name attribute of the xsl:param element.) |
|
| • A name can be repeated if one of the names is in an imported stylesheet and therefore has a lower import precedence. Under these circumstances, the higher import precedence name will always have precedence. |
|
| • Two different parameters can have the same name if they can never occur within the same scope. Therefore no ambiguity can occur (which would be an error). |
|
| • A local and global parameter can have the same name. However, when the local parameter is in scope, the global parameter cannot be accessed. |
|
| If the with-param element contains no content and a select attribute has been not assigned, then the named parameter is set to be the empty string. |
|
| select="expression" |
|
| The optional select attribute is an expression that defines the parameter. If the select attribute is present, then the xsl:with-param element cannot contain any content and is self-closing. If an expression is given, the data type must be Boolean, node-set, number or string. |
|
| If it is a (literal) string, the string must be enclosed within opening and closing quotes and in turn, that default value must be enclosed again in opening and closing quotes. For example: |
|
<xsl:with-param name="car" select=" ' Ford ' " />
Or
<xsl:with-param name="car" select=' " Ford " ' /> |
|
| If the name attribute is assigned, a select attribute is not assigned, and there is no content, then the named parameter is set to be the empty string for the default value. |
|
| Here is the source code of xslt_call_template.xsl that uses xsl:with-parm element: |
|
<?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>
|
|
|
|
|
| XSL Elements Index |
|
| <xsl:text> |
|
<xsl:text disable-output-escaping="yes" | "no" >
</xsl:text> |
|
| The xsl:text element is used to add literal text to the output. This element cannot contain any other XSL elements. It can only contain text. |
|
| Normally, any text that occurs in a stylesheet will be copied to the output regardless if it is enclosed by an xsl:text element. However, there are two primary reasons for using the xsl:text element: |
|
| The first is to control white-space. Extra white-space is preserved by using this element. In other words, a text will be displayed as it really is without any extra white-spaces being removed. |
|
| The second is to handle special characters such as an ampersand (&) or a greater-than sign (>). For example, you may wish a > to be displayed as a >. This is referred to as controlling output escaping. |
|
| This is not a self-closing element. The separate closing element is mandatory. |
|
| disable-output-escaping="yes" | "no" |
|
| The optional disable-output-escaping attribute turns on or off the ability to escape special characters. If set to no, a > will appear as a > in the text. If set to yes, a > will appear as a >. (This attribute should be used with care. |
|
| Remember that XML requires a well-formed code in that all tags or elements must be closed. If set to yes, you could accidentally create a non-well-formed document.) |
|
| Source code for xslt_xsl_text.xsl: |
|
<?xml version="1.0" encoding="iso-8859-1?>
<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>
<xsl:if test="position()=last()">
<span style="width:400px;background-color:
'red'; border: solid 2px inset green">
|
|
<xsl:text>end of the list</xsl:text>
</span>
</xsl:if>
</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>
|
|
| Click here to view the file. |
|
| Source code for ebiz_xsl_text.xml : |
|
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xslt_xsl_text.xsl"?>
<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>Custome
r 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>
<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>
<address>Sector 66, Noida</address>
<age>22</age>
</employee_details>
|
|
<employee_details>
<emp_id>eBIZTECH002</emp_id>
<fname>Shweta</fname>
<lname>Agrwal</lname>
<department>TECHICAL[Java]</department>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>24</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHICAL[Java]</department>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
</ebiz>
|
|
| Output: Try it yourself. |
|
|
|
|
|
| XSL Elements Index |
|
| <xsl:copy> |
|
<xsl:copy use-attribute-sets="name-list" >
</xsl:copy> |
|
| The xsl:copy element copies the current node in the source document to the output. The copy has the same name, namespace, and type as the original node, but any attributes, children, and other descendants are not copied. (Note that you can apply this element recursively to copy attributes and children.) |
|
| The xsl:copy-of element can be used to copy a node set. Children are copied with this element. |
|
| A common use of this element is to make identity transformations. |
|
| use-attribute-sets="name-list" |
|
| The optional use-attribute-sets attribute is a white-space delimited list of attribute sets that are to be applied to the generated node. This is essentially a list of qnames. Aqname 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 use-attribute-sets attribute performs the same purpose as the xsl:attribute element. |
|
| Source code for eBIZ_xsl_copy.xsl: |
|
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xsl_copy.xsl"?>
<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>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHICAL[Java]</department>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
</ebiz>
|
|
| Source code for xsl_copy.xsl: |
|
<xsl:stylesheet xmlns:xsl="http://
www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/ | @* | node()">
<ebizml>
<head>
<title>XSLT XSL:COPY example</title>
</head>
<body>
<xsl:copy>
<xsl:apply-templates select="node()" />
<!--other patterns are/ & @* -->
</xsl:copy>
<hr />
</body>
</ebizml>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
| XSL Elements Index |
|
| <xsl:copy-of> |
|
| Syntax: |
|
| <xsl:copy-of select="expression" /> |
|
| The xsl:copy-of element inserts a duplicate copy of a node set or tree fragment into the output. Perhaps the most important aspect of this element is that it allows you to insert multiple copies of the same set of nodes into different places in the output. For example, you may wish to repeat a page header. |
|
| When a node set is copied, the nodes will be copied into the output in their order of occurrence in the source (this is referred to as document order). Each node and all associated attribute nodes, namespace nodes, children and descendants are copied. In other words, it is a complete, unabridged copy of the set. |
|
| When a root node is copied, all of the children and descendants are copied, but not the root node itself since there can only be one root. When a tree fragment is copied, it is copied exactly to the output. |
|
| For all other circumstances, the xsl:copy-of element behaves exactly like thexsl:value-of element. The value being copied is converted into a string for display in the output. |
|
| In contrast, the xsl:copy element copies the current node in the source document to the output. The copy has the same name, namespace, and type as the original node, but any attributes, children, and other descendants are not copied. |
|
| This is a self-closing element and it cannot contain any child elements or any content. |
|
| select="expression" |
|
| The mandatory select attribute is an expression that identifies which nodes are to be copied. |
|
| Source code for eBIZ_xsl_copy_of.xml: |
|
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xsl_copy_of.xsl"?>
<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>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHICAL[Java]</department>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH004</emp_id>
<fname>Mr Ravish</fname>
<lname>Tiwari</lname>
<department>TECHNICAL[Java]</department>
<designation>Sr. Developer</designation>
<phone>(+91)99990</phone>
<address>Sector 56, Rohni</address>
<age>23</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>
<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>
<address>Sector 66, Noida</address>
<age>22</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH002</emp_id>
<fname>Shweta</fname>
<lname>Agrwal</lname>
<department>TECHICAL[Java]</department>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>24</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHICAL[Java]</department>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
</ebiz>
|
|
| Click here to view the file with XSL or Without XSL. |
|
| Source code of xsl_copy_of.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:copy-of Example</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:use-attribute-sets="tblAttrib">
<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>
|
| Click here to view the XSL file. |
|
| Output: In Mozilla Firefox |
|
 |
|
| in Safari Browser: |
|
 |
|
| In MS IE: |
|
 |
|
|
|
|
| XSL Elements Index |
|
| <xsl:value-of> |
|
<xsl:value-of select="expression"
disable-output-escaping="yes" | "no" /> |
|
| The xsl:value-of element is used to write or display in the result tree a string representation of the value assigned to a specified node. To explain it in another way, this XSLT element causes the value assigned to an XML tag to be displayed as text in the HTML page that we create to display the information in our XML file. There is no limit to the number of xsl:value-of elements that can appear in the code. |
|
| However, each xsl:value-of element can only have one node assigned to it and this is accomplished by using the mandatory select attribute. Remember that a node can occur an unlimited number of times in an XML document. (For example, the <phone> ... </phone> xml tags in our DevGuru Staff List can be used for each staff member.) |
|
| You can use the xsl:for-each element to access each occurrence of a specified node in the order in which they occur in the document. As each occurrence is accessed, you can use the xsl:value-of element to display the value of the current node. |
|
| As an example, you can use the xsl:for-each element to access all of the phone numbers in the <phone> ... </phone> XML tags in our DevGuru Staff List and then display the numbers using the xsl:value-of element. Additionally, you can use thexsl:sort element to define a sorting key which can be used to sort values. |
|
| You can also use the xsl:copy, xsl:copy-of, and xsl:text elements to display values as a string or text. |
|
| If the value is not a string, then the value will be converted to a string. (This is done automatically by calling the String function.) If the value is a Boolean, then the string will display as "true" or "false". If the value is a node-set, then only the first value of the first node in the set is displayed and the values of all other nodes in the set are completely ignored. |
|
| This is a self-closing element and it cannot contain any child elements or any content. |
|
| select="expression" |
|
| The mandatory select attribute assigns the node (by name) to the element. Only one node can be assigned for each occurrence of this element. |
|
| disable-output-escaping="yes" | "no" |
|
| The optional disable-output-escaping attribute specifies how special characters should appear in the output string. A yes dictates that special characters should be displayed as is (i.e., a < or >). The default, no, dictates that special characters should NOT be displayed as is (i.e., a < is displayed as <). |
|
| Source code of xslt_example_numbering.xsl that uses this element: |
|
<?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 example. |
|
|
|
|
| XSL Elements Index |
|
| <xsl:element> |
|
| Syntax: |
|
<xsl:element name="element-name" namespace="URI" use-attribute-sets="qname" >
</xsl:element> |
|
| The xsl:element element is used to create and name an element (node) that can appear in the output. This ability to create both custom elements and attributes, and to display the results, is a major reason why stylesheets generated by XSL are a very sophisticated approach to displaying XML data. |
|
| There are two ways to add attributes to a created element: by using the xsl:attribute,xsl:copy, and the xsl:copy-of elements or, by using the optional use-attribute-sets attribute of the xsl:element element. Any attributes created using the use-attribute-sets attribute that have the same name as attributes created using the xsl:attribute, xsl:copy, and the xsl:copy-of elements, will be overwritten. |
|
| There is a firm restriction regarding the addition of attributes. After a child node has been added to an element, no additional attributes can be added to the parent node. This rule is required so that the XSL processor does not have to store the result tree in memory. Otherwise, if attributes could be added at a later time, the result tree would have to be stored while the XSL processor searched the entire tree for additional attributes. |
|
| Note, you can use the xsl:copy element to copy a node from the source document. |
|
This element is not self-closing. The separate closing element is mandatory .
name="element-name" |
|
| The mandatory name attribute is the qname of the element to be created. 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:zipcodeor zipcode). |
|
| The name is one of a very few attributes in XSLT 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:element name="{$emp_name}" /> |
|
| namespace="URI" |
|
| The optional namespace attribute is the namespace URI (Universal Resource Identifier) of the generated element. 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.) |
|
| use-attribute-sets="qname" |
|
| The optional use-attribute-sets attributes allows the addition of attributes to the created element. It is composed of a white space delimited list (set) of the attributes to be added. This is an alternative to using the xsl:attribute element. |
|
<?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 XSL file. |
|
| Click here to view the XML file with the above XSL file. |
|
| Output: |
|
 |
|
|
|
|
| XSL Elements Index |
|
| <xsl:if> |
|
| Syntax: |
|
| <xsl:if test="expression" > </xsl:if> |
|
| 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. |
|
| Source code of xsl_if.xsl element: |
|
<?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:copy-of Example</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:use-attribute-sets="tblAttrib">
<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>
|
|
| Click here to view the XSL file. |
|
|
|
|
| XSL Elements Index |
|
| <xsl:choose> |
|
| Syntax: |
|
<xsl:choose> <xsl:when test="expression">
...
</xsl:when>
... <xsl:otherwise>
...
</xsl:otherwise>
</xsl:choose>
|
|
| The xsl:choose element is used to make a choice when there are two or more possible courses of action. It provides a means for conducting multiple conditions testing. |
|
| The xsl:choose element must contain one or more xsl:when elements and can contain only one optional xsl:otherwise element (which must occur after all of the xsl:whenelements). If the xsl:choose element only contains one xsl:when element, then for all practical purposes, it behaves just like the xsl:if element. |
|
| When faced with three or more choices, this element behaves like an if-then-else statement (or a Select Case) as found in numerous other computer languages. |
|
| Each xsl:when element is examined in the order of occurrence. If and when the conditions of the test expression are satisfied (returns True), the code contained in that element is executed. |
|
| Then the xsl:choose element is automatically exited and all further xsl:when elements are ignored and are not tested. The optional xsl:otherwise element is also automatically ignored. |
|
| If none of the test conditions in any xsl:when element is satisfied (all return False), then the xsl:otherwise element is automatically selected (if it is present) and the code associated with that element is executed. If there is no xsl:otherwise element, then the xsl:choose element is exited. |
|
| This element has no attributes. It is not a self-closing tag. The separate closing element is mandatory. |
|
| Source code for xsl_choose.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>Department</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:choose 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">
<xsl:sort data-type="number" order="descending" select="age" />
<tr>
<td><xsl:value-of select="fname" />
<xsl:value-of select="lname" /></td>
|
|
<td><xsl:value-of select="address" /></td>
<xsl:choose>
<xsl:when test="department-sub ='Java'">
<td style="background-color:pink">
<xsl:value-of select="department" /
><xsl:text>[</xsl:text>
<xsl:value-of select="department-sub" />
<xsl:text>]</xsl:text></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="department" /> </td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</ebizml>
</xsl:template>
</xsl:stylesheet>
|
|
| Click here to view the XSL file |
|
| Source code of eBIZ_xsl_choose.xml: |
|
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xsl_choose.xsl"?>
<ebiz>
<employee_details>
<emp_id>eBIZTECH001</emp_id>
<fname>Mr Aman Kumar</fname>
<lname>Singh</lname>
<department>TECHICAL</department>
<department-sub>Java</department-sub>
<designation>Sr. Developer</designation>
<phone> 32942</phone>
<address>Sector 44, Noida</address>
<age>27</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
|
|
<lname>Jain</lname>
<department>TECHICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH004</emp_id>
<fname>Mr Ravish</fname>
<lname>Tiwari</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Sr. Developer</designation>
<phone>(+91)99990</phone>
<address>Sector 56, Rohni</address>
<age>23</age>
|
|
</employee_details>
<employee_details>
<emp_id>eBIZCSS001</emp_id>
<fname>Mrs Sunita</fname>
<lname>Singhania</lname>
<department>Customer Su
pport[Web Assist]</department>
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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</department>
<department-sub>Java</department-sub>
<designation>Jr. DEVELOPER</designation>
<phone> (+91)99990</phone>
|
|
<address>Sector 66, Noida</address>
<age>22</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH002</emp_id>
<fname>Shweta</fname>
<lname>Agrwal</lname>
<department>TECHICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>24</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
</ebiz>
|
|
| Click to view the file with XSL or without XSL. |
|
 |
|
|
|
|
| XSL Elements Index |
|
| <xsl:when> |
|
| Syntax: |
|
<xsl:choose>
<xsl:when test="expression">
... </xsl:when>
...
<xsl:otherwise>
...
</xsl:otherwise>
</xsl:choose>
|
|
| The xsl:when element is a child of the xsl:choose element. The xsl:choose element is used to make a choice when there are two or more possible courses of action. It provides a means for conducting multiple condition testing. |
|
| The xsl:choose element must contain one or more xsl:when elements and can contain only one optional xsl:otherwise element (which must occur after all of the xsl:whenelements). If the xsl:choose element only contains one xsl:when element, then for all practical purposes, it behaves just like the xsl:if element. |
|
| When faced with three or more choices, these elements behave similar to an if-then-else statement (or a Select Case) as found in numerous other computer languages. |
|
| The purpose of xsl:when element is to contain a Boolean expression that can be tested. The test must return a value of either true or false. Each xsl:when element is examined in the order of occurrence. |
|
| If and when the conditions of the test expression are satisfied (returns True), the code contained in that element is executed. Then the xsl:choose element is automatically exited and all further xsl:when elements are ignored and they are not tested. The optional xsl:otherwise element is also automatically ignored. |
|
| If none of the test conditions in any xsl:when element is satisfied (all return False), then the xsl:otherwise element is automatically selected (if it is present) and the code associated with that element is executed. If there is no xsl:otherwise element, then the xsl:choose element is exited. |
|
| This element is not a self-closing tag. The separate closing element is mandatory. |
|
| test="expression" |
|
| The mandatory test attribute is a Boolean expression that is the test condition to be satisfied. A True signifies that the test conditions have been met. A False signifies that the test conditions have not been met. |
|
| We use the our XML file for our example with the following header: |
|
| <?xml-stylesheet type="text/xsl" href="xsl_when.xsl"?> |
|
| and we name it: xsl_when.xml: |
|
<?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>Department</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:choose 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">
<xsl:sort data-type="number" order="descending" select="age" />
<tr>
<td><xsl:value-of select="fname" />
<xsl:value-of select="lname" /></td>
<td><xsl:value-of select="address" /></td>
<xsl:choose>
<xsl:when test="department-sub ='Java'">
<td style="background-color:pink"> <
xsl:value-of select="department" /><xsl:text>
[</xsl:text><xsl:value-of select="department-sub" />
<xsl:text>]</xsl:text></td>
</xsl:when>
<xsl:when test="department ='TECHNICAL'">
<td style="background-color:#
FFCC99;color:white;font-weight:bold">
<xsl:value-of select="department" /><xsl:text>
[</xsl:text><xsl:value-of select="department-sub" />
<xsl:text>]</xsl:text></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="department" /> </td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="department='TECHNICAL'">
<td style="background-color:#F
FCC99;color:white;font-weight:bold">
<xsl:value-of select="designation" />
</td>
</xsl:when>
<xsl:otherwise>
<td style="font-weight:bold">
<xsl:value-of select="designation" />
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</ebizml>
</xsl:template>
</xsl:stylesheet>
|
|
| Click here to view the XSL file |
|
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xsl_when.xsl"?>
<ebiz>
<employee_details>
<emp_id>eBIZTECH001</emp_id>
<fname>Mr Aman Kumar</fname>
<lname>Singh</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Sr. Developer</designation>
<phone> 32942</phone>
<address>Sector 44, Noida</address>
<age>27</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
|
|
<employee_details>
<emp_id>eBIZTECH004</emp_id>
<fname>Mr Ravish</fname>
<lname>Tiwari</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Sr. Developer</designation>
<phone>(+91)99990</phone>
<address>Sector 56, Rohni</address>
<age>23</age>
</employee_details>
<employee_details>
<emp_id>eBIZCSS001</emp_id>
<fname>Mrs Sunita</fname>
<lname>Singhania</lname>
<department>Customer
Support[Web Assist]</department>
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. DEVELOPER</designation>
<phone> (+91)99990</phone>
<address>Sector 66, Noida</address>
<age>22</age>
</employee_details>
|
|
<employee_details>
<emp_id>eBIZTECH002</emp_id>
<fname>Shweta</fname>
<lname>Agrwal</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>24</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
</ebiz>
|
|
 |
|
|
|
|
| XSL Elements Index |
|
| <xsl:otherwise> |
|
| Syntax: |
|
<xsl:choose>
<xsl:when test="expression">
...
</xsl:when>
... <xsl:otherwise>
... <xsl:otherwise>
</xsl:choose>
|
|
| The xsl:otherwise element is an optional child of the xsl:choose element. Thexsl:choose element is used to make a choice when there are two or more possible courses of action. It provides a means for conducting multiple conditions testing. |
|
| The xsl:choose element must contain one or more xsl:when elements and can contain only one optional xsl:otherwise element (which must occur after all of the xsl:whenelements). If the xsl:choose element only contains one xsl:when element, then for all practical purposes, it behaves just like the xsl:if element. |
|
| When faced with three or more choices, these elements behave similar to an if-then-else statement (or a Select Case) as found in numerous other computer languages. |
|
| The purpose of the xsl:when element is to contain a Boolean expression that can be tested. The test must return a value of either true or false. Each xsl:when element is examined in the order of occurrence. |
|
| If and when the conditions of the test expression are satisfied (returns True), the code contained in that element is executed. Then the xsl:choose element is automatically exited and all further xsl:when elements are ignored and they are not tested. In this case, the optional xsl:otherwise element is also automatically ignored. |
|
| If none of the test conditions in any xsl:when element is satisfied (all return False), then the xsl:otherwise element is automatically selected (if it is present) and the code associated with that element is executed. If there is no xsl:otherwise element, then thexsl:choose element is exited. |
|
| This element has no attributes. It is not a self-closing tag. The separate closing element is mandatory. |
|
| Given below is the source code of xsl_when.xsl that uses xsl:otherwise: |
|
<!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>Department</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:choose 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">
<xsl:sort data-type="number" order="descending" select="age" />
<tr>
<td><xsl:value-of select="fname" />
<xsl:value-of select="lname" /></td>
<td><xsl:value-of select="address" /></td>
<xsl:choose>
<xsl:when test="department-sub ='Java'">
<td style="background-color:pink"> <
xsl:value-of select="department" />
<xsl:text>[</xsl:text><xsl:value-of select="department-sub" />
<xsl:text>]</xsl:text></td>
</xsl:when>
<xsl:when test="department ='TECHNICAL'">
<td style="background-color:
#FFCC99;color:white;font-weight:bold">
<xsl:value-of select="department" />
<xsl:text>[</xsl:text
><xsl:value-of select="department-sub" />
<xsl:text>]</xsl:text></td>
|
|
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="department" /> </td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="department='TECHNICAL'">
<td style="background-color:#
FFCC99;color:white;font-weight:bold">
<xsl:value-of select="designation" />
</td>
</xsl:when>
<xsl:otherwise>
<td style="font-weight:bold">
<xsl:value-of select="designation" />
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</ebizml>
</xsl:template>
</xsl:stylesheet>
|
|
| Click here to view the XSL file. |
|
|
|
|
| XSL Elements Index |
|
| <xsl:message> |
|
| Syntax: |
|
| <xsl:message terminates="yes" | "no" > </xsl:message> |
|
| The xsl:message element is primarily used to report errors by displaying a text message and related information of interest in the output. This element can contain almost any other XSL element. |
|
| For example, you can use the xsl:text element to add literal text to thexsl:message element and you can use the xsl:value-of element to display values. |
|
| Exactly how the text contained in the xsl:message element (and any associated stylesheet error messages) will be displayed in the output will be determined by the XSLprocessor. |
|
| This element also provides a mechanism that gives you the choice to quit the XSLprocessor (terminate the process) when an error is encountered or to allow the process to continue (the default). |
|
| Alternatively, the xsl:comment element can be used to debug errors. This is not a self-closing element. The separate closing element is mandatory. |
|
| terminates="yes" | "no" |
|
| The optional terminates attribute provides the choice of quitting the process or continuing the process if an error is encountered. If set to no, the error in the stylesheet is reported and the process continues. This is the default. If set to yes, the error in the stylesheet is reported and the process terminates. |
|
| In this example, we test to see if a [department-sub] is the empty string in case department of [TECHNICAL] department. If yes, we exit and display a message. |
|
| Source code of xsl_message.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>Department</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:choose Example</title>
</head>
<body>
<span style="width 600px;border:
2px outset blue solidl;display:block">
</span><br /><!--[CDATA[<xsl:sort data-type=
"number" order="descending" select="age" />]]-->
<table xsl:use-attribute-sets="tblAttrib">
<xsl:copy-of select="$tbl" />
<xsl:for-each select="ebiz/employee_details">
<tr>
<td><xsl:value-of select="fname" />
<xsl:value-of select="lname" /></td>
<td><xsl:value-of select="address" /></td>
<xsl:choose>
|
|
<xsl:when test="department-sub ='Java'">
<td style="background-color:pink">
<xsl:value-of select="department" /><xsl:text>
[</xsl:text><xsl:value-of select="department-sub" />
<xsl:text>]</xsl:text></td>
</xsl:when>
<xsl:when test="department ='TECHNICAL'">
<td style="background-color:#
FFCC99;color:white;font-weight:bold">
<xsl:value-of select="department" />
<xsl:if test="department-sub=''">
<xsl:message terminate="yes">
[Department-sub not Available]
</xsl:message>
</xsl:if>
<xsl:text>[</xsl:text><xsl:value-o
f select="department-sub" />
<xsl:text>]</xsl:text></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select
="department" /> </td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
|
|
<xsl:when test="department='TECHNICAL'">
<td style="background-color:#
FFCC99;color:white;font-weight:bold">
<xsl:value-of select="designation" />
</td>
</xsl:when>
<xsl:otherwise>
<td style="font-weight:bold">
<xsl:value-of select="designation" />
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</ebizml>
</xsl:template>
</xsl:stylesheet>
|
| Click here to view the XSL file. |
|
| Source code for eBIZ_xsl_message.xml: |
|
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xsl_message.xsl"?>
<ebiz>
<employee_details>
<emp_id>eBIZTECH001</emp_id>
<fname>Mr Aman Kumar</fname>
<lname>Singh</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Sr. Developer</designation>
<phone> 32942</phone>
<address>Sector 44, Noida</address>
<age>27</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
|
|
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH004</emp_id>
<fname>Mr Ravish</fname>
<lname>Tiwari</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Sr. Developer</designation>
<phone>(+91)99990</phone>
<address>Sector 56, Rohni</address>
<age>23</age>
|
|
</employee_details>
<employee_details>
<emp_id>eBIZCSS001</emp_id>
<fname>Mrs Sunita</fname>
<lname>Singhania</lname>
<department>Custome
r Support[Web Assist]</department>
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. DEVELOPER</designation>
<phone> (+91)99990</phone>
<address>Sector 66, Noida</address>
<age>22</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH002</emp_id>
<fname>Shweta</fname>
<lname>Agrwal</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>24</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
|
|
</employee_details><employee_details>
<emp_id>eBIZAC004</emp_id>
<fname>ANAMIKA</fname>
<lname>SINGH</lname>
<department>Accounts</department>
<department-sub></department-sub>
<designation>Jr. Accountant</designation>
<phone>032942 </phone>
<address>Sector 99, Noida</address>
<age>21</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH004</emp_id>
<fname>Nilofar</fname>
<lname>Khan</lname>
<department>TECHNICAL</department>
<department-sub></department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
</ebiz>
|
| Click here to view the XML file without XSL or Click here to view the file with XSL. |
|
|
|
|
| XSL Elements Index |
|
| <xsl:variable> |
|
| Syntax: |
|
| <xsl:variable name="qname" > </xsl:variable> |
|
Or:
<xsl:variable name="qname" select="expression" /> |
|
| 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 thexsl: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:transformelements). 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. |
|
| name="qname" |
|
| The mandatory name attribute is the qname of the expression. 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). Note the following rules concerning when two different variables can have the same name. (The same rules apply to the name attribute of the xsl:param element.) |
|
• A name can be repeated if one of the names is in an imported stylesheet and therefore has a lower import precedence. Under these circumstances, the higher import precedence
name will always have precedence.
• Two different variables can have the same name if they can never occur within the same scope. Therefore no ambiguity can occur (which would be an error).
• A local and global variable can have the same name. However, when the local variable is in scope, the global variable cannot be accessed. |
|
If the variable element contains no content and a select attribute has been not assigned, then the named variable is set to be the empty string.
select="expression" |
|
| The optional select attribute is an expression that defines the variable. If the select attribute is present, then the xsl:variable element cannot contain any content and is self-closing. If an expression is given, the data type must be Boolean, node-set, number or string. If it is a literal string, the string must be enclosed within opening and closing quotes and in turn, that value must be enclosed again in opening and closing quotes. For example: |
|
<xsl:variable name="emp_name" select=" ' fname ' " />
Or
<xsl:variable name="emp_name" select=' " fname " ' /> |
|
| If the name attribute is assigned, a select attribute is not assigned, and there is no content, then the named variable is set to be the empty string. |
|
| Source code of xsl_variable.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: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:choose 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">
<xsl:sort data-type="number" order="descending" select="age" />
<tr>
<td><xsl:value-of select="fname" /
> <xsl:value-of select="lname" /></td>
<td><xsl:value-of select="address" /></td>
<xsl:choose>
<xsl:when test="department-sub ='Java'">
<td style="background-color:pink">
<xsl:value-of select="department" /><xsl:text>
[</xsl:text><xsl:value-of select="department-sub" />
<xsl:text>]</xsl:text></td>
</xsl:when
<xsl:when test="department ='TECHNICAL'">
<td style="background-color:#
FFCC99;color:white;font-weight:bold">
<xsl:value-of select="department" />
<xsl:text>[</xsl:text><xsl:value-of se
lect="department-sub" /><xsl:text>]</xsl:text></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="department" /> </td>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="department='TECHNICAL'">
|
|
<td style="background-color:
#FFCC99;color:white;font-weight:bold">
<xsl:value-of select="designation" />
</td>
</xsl:when>
<xsl:otherwise>
<td style="font-weight:bold">
<xsl:value-of select="designation" />
</td>
</xsl:otherwise>
</xsl:choose>
<td>
<xsl:value-of select="age" />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</ebizml>
</xsl:template>
</xsl:stylesheet>
|
|
| Click here to view the XSL file and click here to view the XML file with this XSL. |
|
 |
|
|
|
|
| XSL Elements Index |
|
| <xsl:decimal-format> |
|
| Syntax: |
|
<xsl:decimal-format
decimal-separator="character"
digit="character"
grouping-separator="character"
infinity="string"
minus-sign="character"
name="qname"
NaN="string"
pattern-separator="character"
percent="character"
per-mille="character"
zero-digit="character"
/>
|
|
| The xsl:decimal-format element defines the symbols and characters used by the format-number function to convert numbers to strings. This element can be used more than once, but with certain limitations. |
|
| Each element can have an optional name value assigned to it by using by the name attribute. However, you cannot repeat name values. Further, you can only omit the name attribute once. |
|
| This element does not effect the behavior of the xsl:number and the xsl:value-of elements when they are used to format a number for display in the output. Nor does it effect the string function which has a default procedure for converting numbers to strings. |
|
| The xsl:decimal-format element can only be a child of the xsl:stylesheet or thexsl:transform elements. |
|
| This is a self-closing element and it cannot contain any child elements or any content. |
|
| decimal-separator="character" |
|
The optional decimal-separator attribute defines what character is used to separate the integer and fraction part of a number. The default is a dot (.).
digit="character" |
|
The optional digit attribute defines what character is used to signify that a digit is needed in a format pattern. The default is the hash mark (#).
grouping-separator="character" |
|
The optional grouping-separator attribute defines what character is used to separate groups of digits (for example: 1,763,920). The default is a comma (,).
infinity="string" |
|
The optional infinity attribute defines what string is used to represent that the value is infinite. The default is the string, "infinity".
minus-sign="character" |
|
The optional minus-sign attribute defines what character is used to represent a minus sign. The default is the hyphen (-).
name="qname" |
|
The optional name attribute assigns a qname to the element. If the name attribute is omitted, then you are declaring that this is the default xsl:decimal-format element. You cannot repeat names. Note that this name can be used as the optional third argument to the format-number function.
NaN="string" |
|
The optional NaN attribute defines what string is used to indicate that the value is not a number. The default is the string, "NaN".
pattern-separator="character" |
|
The optional pattern-separator attribute defines what character is used to separate positive and negative sub-patterns in a format pattern. The default is the semicolon (;).
percent="character" |
|
The optional percent attribute defines what character is used to represent a percent sign. The default is the percent sign (%).
per-mille="character" |
|
The optional per-mille attribute defines what character is used to represent the per thousand sign. The default is the Unicode per mille character (‰).
zero-digit="character" |
|
| The optional zero-digit attribute defines what character is used to represent the digit zero. The default is (0). |
|
| Code fragment below, shows how to format for European currency: |
|
| <xsl:decimal-format name="euro_currency" decimal-separator="," grouping-separator="."> |
|
| Source code for xsl_decimal_format.xsl: |
|
<xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:decimal-format name="staff" digit="D" />
<xsl:template match="/">
<html>
<body>
<xsl:value-of select='format-number(123456789, "#.000")' />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
| Click here to view the file. |
|
|
|
|
| XSL Elements Index |
|
| <xsl:key> |
|
| Syntax: |
|
| <xsl:key match="pattern" name="qname" use="expression" > </xsl:key> |
|
| The xsl:key element is used to declare a named key that can be used by the key function in expressions and patterns. The key function has two arguments: the key name and the value (consider this to be a key-value pair). The appropriate use of these key-value pairs can permit easy access to information in complex XML documents. |
|
| A key does not have to be unique. Further, a key can refer to more than one node and a node can have more than one key. |
|
| There is no limit to the number of the xsl:key elements that can occur. However, eachxsl:key element can only be a child of the xsl:stylesheet or the xsl:transformelements. It cannot contain any elements as content, nor can it appear inside a template. |
|
| The xsl:key element alerts the XSLT processor to create an indexed data structure for the key expressions ahead of time. This indexed data structure will be used by the key function. If there are no xsl:key elements, then the time-consuming indexing is not performed. |
|
This is not a self-closing element. The separate closing element is mandatory.
match="pattern" |
|
The mandatory match attribute defines the nodes to which the key will be applied.
name="qname" |
|
The mandatory name attribute is a qname that identifies the key. 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="expression" |
|
| The mandatory use attribute is an expression or string that is used to determine the value of the key for each node. |
|
| Example below searches for members of Java Department and display the records. |
|
| Source Code for xsl_key.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>Department</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:key name="emplist"
match="employee_details" use="department-sub" />
<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:use-attribute-sets="tblAttrib">
<xsl:copy-of select="$tbl" />
<xsl:for-each select="ebiz/employee_details">
<xsl:sort data-type="number" order="descending" select="age" />
<tr>
<td><xsl:value-of select="fname" /> <
xsl:value-of select="lname" /></td>
<td><xsl:value-of select="address" /></td>
<xsl:choose>
<xsl:when test="department-sub ='Java'">
<td style="background-color:pink">
<xsl:value-of select="department" /><xsl:text>
[</xsl:text><xsl:value-of select="department-sub" />
<xsl:text>]</xsl:text></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="department" /> </td>
|
|
</xsl:otherwise>
</xsl:choose>
<td><xsl:value-of select="designation" /></td>
</tr>
</xsl:for-each>
</table>
<hr />
<br />
<span style="background-color:pink; width:100%;margin: 0px 0px 0px 0px">
<xsl:text>Using Key-Value pair to access
Data of Java Team members </xsl:text>
</span>
<br />
<div style="background-color: #FFCC99; border:
solid 2px groove #663333;width:60%;
padding-top: 10px;padding-left:5px">
<table xsl:use-attribute-sets="tblAttrib">
<xsl:copy-of select="$tbl" />
<xsl:for-each select="key('emplist','Java')" >
<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="department" /></td>
<td><xsl:value-of select="designation" /></td>
</tr>
</xsl:for-each>
</table>
</div>
</body>
</ebizml>
</xsl:template>
</xsl:stylesheet>
|
|
| Click here to view the XSL file. |
|
| Source code for eBIZ_xsl_key.xml: |
|
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="xsl_key.xsl"?>
<ebiz>
<employee_details>
<emp_id>eBIZTECH001</emp_id>
<fname>Mr Aman Kumar</fname>
<lname>Singh</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Sr. Developer</designation>
<phone> 32942</phone>
<address>Sector 44, Noida</address>
<age>27</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
|
|
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH004</emp_id>
<fname>Mr Ravish</fname>
<lname>Tiwari</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Sr. Developer</designation>
<phone>(+91)99990</phone>
<address>Sector 56, Rohni</address>
<age>23</age>
</employee_details>
<employee_details>
<emp_id>eBIZCSS001</emp_id>
<fname>Mrs Sunita</fname>
<lname>Singhania</lname>
<department>Custome
r Support[Web Assist]</department>
|
|
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>
|
|
<department-sub>NA</department-sub>
<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>
<department-sub>NA</department-sub>
<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>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. DEVELOPER</designation>
<phone> (+91)99990</phone>
|
|
<address>Sector 66, Noida</address>
<age>22</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH002</emp_id>
<fname>Shweta</fname>
<lname>Agrwal</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>24</age>
</employee_details>
<employee_details>
<emp_id>eBIZTECH003</emp_id>
<fname>Shalu</fname>
<lname>Jain</lname>
<department>TECHNICAL</department>
<department-sub>Java</department-sub>
<designation>Jr. Programmer</designation>
<phone> 32942</phone>
<address>Sector 66, Noida</address>
<age>23</age>
</employee_details>
</ebiz>
|
| Click here to view the file with XSL or click here to view the file without XSL. |
|
|
|
|
| XSL Elements Index |
|
| <xsl:fallback> |
|
| Syntax: |
|
<xsl:fallback>
</xsl:fallback> |
|
| The xsl:fallback element is designed to provide fallback code that can be run as an alternative when an XSLT processor fails to support an element. |
|
| Normally, when an XSLT element is not recognized by the XSLT processor an error occurs. The concept behind the xsl:fallback element is to provide a mechanism that will allow a procedure to keep running whenever an XSLT element is encountered that is not supported by an XSLT processor. |
|
| For example, view these Microsoft proprietary elements. Undoubtedly, as XSLTbecomes more mainstream, additional proprietary elements will become more common. A similar problem may also arise as newer and newer versions of XSLT become available and various elements are added or removed from the standard. |
|
| In the future, it may become commonplace to use the xsl:fallback element as a means of insuring portability between different browsers and XSLT processors. This element has no attributes. This is not a self-closing element. The separate closing element is mandatory. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 comments: