[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

preserve-space and strip-space?

Subject: preserve-space and strip-space?
From: "Kirk Allen Evans" <kaevans@xxxxxxxxx>
Date: Mon, 17 Sep 2001 08:28:52 -0400
space within xsl tags
Maybe I am wrong on what strip-space and preserve-space are supposed to do.
Using the following XML document, I pad each element's values with spaces.

<?xml version="1.0" encoding="UTF-8" ?>
<links>
 <link>     testing pre-stripping</link>
 <link>testing post-stripping         </link>
 <link>         testing any stripping      </link>
</links>

Then, applying the stylesheet, I specify the "link" element is to be
stripped.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:strip-space elements="link" />
 <xsl:template match="/">
  <xsl:for-each select="links/link">
   <xsl:text>[</xsl:text>
   <xsl:value-of select="." />
   <xsl:text>]</xsl:text>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

I would expect the result as
<?xml version="1.0" encoding="UTF-16"?>[testing pre-stripping][testing
post-stripping][testing any stripping]

Instead, the result is
<?xml version="1.0" encoding="UTF-16"?>[     testing pre-stripping][testing
post-stripping         ][         testing any stripping      ]

If stripping does not affect the elements' values, then what does the
whitespace preserve and stripping preserve or strip?  I thought that it
might be whitespace within the tag delimiters, so I used the following XML
doc.

<?xml version="1.0" encoding="UTF-8" ?>
<links>
 <link  >     testing pre-stripping</link   >
 <link   >testing post-stripping         </link   >
 <link   >         testing any stripping      </link   >
</links>

The following stylesheet explicitly preserves space, but seems to have no
effect.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:preserve-space elements="link" />
 <xsl:template match="/">
  <xsl:apply-templates />
 </xsl:template>
 <xsl:template match="@* | node()">
  <xsl:copy>
   <xsl:apply-templates select="@* | node()" />
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>


The result of this transformation is the same as the input, but the space
within the element tags is gone, so preserve-space had no noticeable effect
here.

<?xml version="1.0" encoding="UTF-16"?><links>
 <link>     testing pre-stripping</link>
 <link>testing post-stripping         </link>
 <link>         testing any stripping      </link>
</links>

--
Kirk Allen Evans
http://www.vbdna.net/rant

God bless the USA




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.