This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
xsl:strip-space does not work?
Nisheet Verma writes:
> I am using a xml file which looks like, the following ( I have removed
> insignificant text to improve readability)
>
> ?xml version="1.0"?>
> <Catalog id="C31">
> <object uri="http://developler.com/classdef;132">
> <property uri="http://developer.com/propertyType;193">
> 1698.0||
> </property
> </object>
> </Catalog>
>
> I want to parse it using the following XSL
>
> <?xml version="1.0" ?>
> <!-- Passes a node set from one template to another -->
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:strip-space elements="*" />
> <xsl:output method="xml" indent="yes" />
> <xsl:template match="object" >
> <PRODUCT_ITEM >
> <PRICE>
> <xsl:value-of select="property/@uri"/>
> </PRICE>
> </xsl:template>
> </xsl:stylesheet>
>
> The out put looks like this
>
> <PRODUCT_ITEM>
> <PRICE>
> 1698.0||
> </PRICE>
> </PRODUCT_ITEM>
>
> I don't know why xsl:strip does not strip out the whitespaces around PRICE
> tag. I can use normalize-space() to make it work but that would be a hack.
> I guess, xsl:strip=space should work, or am I using it incorrectly?
>From what I read in "XSLT Programmer's Reference" strip-space only
eliminates text nodes that consist entirely of whitespace, so it won't
have any affect on your "property" node which also has some digits, a
period ans two vertical bars in it as well as the whitespace.
I think you want to change your template to
<xsl:template match="object" >
<PRODUCT_ITEM >
<PRICE>
<xsl:value-of select="normalize-space(property/@uri)"/>
</PRICE>
</xsl:template>
which uses the normalize-space function to remove leading and trailing
whitespace from the attribute value.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list