<xsl:preserve-space> |
The xsl:preserve-space element is used to keep white-space only nodes in the output. Note that the default is to leave white-space only nodes. Therefore, it is only necessary to use the xsl:preserve-space element when you use the xsl:strip-space element and wish to insure that certain white-space nodes are not removed. By white-space, we refer to carriage returns, line feeds, spaces and tabs. No text or numbers appear in the node. |
The related xsl:strip-space element is used to remove white-space only nodes so that they do not appear in the output. This is a self-closing element and it cannot contain any child elements or any content. |
elements=”names” |
The mandatory elements attribute is a white-space delimited list of the names of the elements in which all of the white-space nodes must not be removed. You can also use generic names with wild cards. |
We use the eBIZ_com_Staff XML file for our example with the following header: <?xml-stylesheet type=”text/xsl” href=”xslt_example_preservespace.xsl”?> and we name it: eBIZ_com_Staff.xml |
Code for xslt_example_preservespace1.xsl: |
<?xml version="1.0" encoding="iso-8859-1"?> <!-- DWXMLSource="sample23.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: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:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script> var i=0; function mm() { i+=1; document.data.srno.innerHTML=""+i; } </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Sample XSL Document</title> <style type="text/css"> <xsl:comment> .style3 {font-family: Geneva, Arial, Helvetica, sans-serif; color: #0033FF; } </xsl:comment> </style> </head> <body> |
<table width="59%" border="1" cellspacing="0" cellpadding="1" id="data"> <tr> <td width="9%" nowrap="nowrap" bgcolor="#6699FF"><strong>Sr no </strong></td> <td width="22%" bgcolor="#6699FF"> <strong>Employee ID </strong></td> <td width="30%" bgcolor="#6699FF"> <strong>Name</strong></td> <td width="20%" bgcolor="#6699FF"> <strong>Department</strong></td> <td width="19%" bgcolor="#6699FF"> <strong>Designation</strong></td> <td width="19%" nowrap="nowrap" b gcolor="#6699FF"><strong>Phone No </strong></td> <td width="19%" nowrap="nowrap " bgcolor="#6699FF"><strong>Address </strong></td> </tr> <xsl:for-each select="ebiz/employee_details"> <tr> <td><span class="style3">. <script>i=i+1;document.write(i);</script> </span></td> |
<td nowrap="nowrap"><span class="style3"> <xsl:value-of select="emp_id" /></span></td> <td nowrap="nowrap"><span class="style3" ><xsl:value-of select="fname"> </xsl:value-of> <xsl:value-of select="lname"></xsl:value-of></span></td> <td nowrap="nowrap"><xsl:value-of select="department" /></td> <td nowrap="nowrap"><xsl:value-of select="designation" /></td> <td nowrap="nowrap"><xsl:value-of select="phone" /></td> <td nowrap="nowrap"><xsl:value-of select="address"/></td > </tr></xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> |
Check Also
XSLT Element Index
XML is one of the most important of all recent innovations to hit the web. …