xsl:preserve-space
xsl:text
ELEMENT: xsl:strip-space
<xsl:strip-space
elements="names"
/>
The
xsl:strip-space
element is used to remove white-space only nodes so that they do not appear in the output. By white-space, we refer to carriage returns, line feeds, spaces and tabs. No text or numbers appear in the node.
The related
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.
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 can be removed. You can also use generic names with wild cards. For example,
elements="*"
removes all white-space nodes in all elements.
We use the
DevGuru Staff List XML file
for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_stripspace.xsl"?>
and we name it: xslt_example_stripspace.xml
In this example, white-space phone and address nodes are removed.
Code for xslt_example_stripspace.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-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information