Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
xsl:strip-space
xsl:text
ELEMENT: xsl:preserve-space
<xsl:preserve-space
elements="names"
/>
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
DevGuru Staff List XML file
for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_preservespace.xsl"?>
and we name it: xslt_example_preservespace.xml
In this example, we preserve white-space nodes for name and remove white nodes for phone and address.
Code for xslt_example_preservespace.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="phone address" />
<
xsl:preserve-space elements="name" /
>
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="devguru_staff/programmer">
<div>
<xsl:value-of select="name" />
<br />
<xsl:value-of select="dob" />
<br />
<xsl:value-of select="age" />
<br />
<xsl:value-of select="address" />
<br />
<xsl:value-of select="phone" />
<hr />
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Click to view output in separate window
- requires Internet Explorer
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information