" some value "
transformed to
"some value"
gotta love padded CHAR(25) in the DB :(
Use normalize ;)
Manfred
XPath function: string normalize-space (string?)
Standard excerpt:
The normalize-space function returns the argument string with whitespace
normalized by stripping leading and trailing whitespace and replacing
sequences of whitespace characters by a single space. Whitespace
characters are the same as those allowed by the S production in XML. If
the argument is omitted, it defaults to the context node converted to a
string, in other words the string-value of the context node.
**** notice it modifies spaces IN THE STRING also :P
I am no XSLT guru... Is there a "normalize" vs "normalize-space" that
you were referring to?
You can use this one too. Normalize would do it for the entire XML document,
while the function expects an input
XSLT doesn't have the trim() or the replace() functions which drives me
crazy. normalize-space() is useless. You have to do recursive calls for
now until XPath 2.0 gives us more options.
Here's a solution for you:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:copy>
<xsl:apply-templates select="data" />
</xsl:copy>
</xsl:template>
<xsl:template match="data">
<xsl:copy>
<xsl:for-each select="datum">
<xsl:copy>
<xsl:call-template name="trim">
<xsl:with-param name="input" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template name="trim">
<xsl:param name="input"/>
<xsl:choose>
<xsl:when test="starts-with($input,' ')">
<xsl:call-template name="trim">
<xsl:with-param name="input" select="substring-after($input,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="substring($input, string-length($input) ) = ' ' ">
<xsl:call-template name="trim">
<xsl:with-param name="input" select="substring($input, 1,
string-length($input)-1)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$input"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
and the test data:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="trim.xslt" ?>
<data>
<datum> x </datum>
<datum> xx </datum>
<datum> x x </datum>
<datum> x x </datum>
<datum> x x x x </datum>
</data>
--Doug Hoff
we ended up skipping transforms on each field and just traversed the
entire DOM, in memory, with node.setValue(node.getValue().trim())
* everything is not a Nail ;)
Xanian
The simple solution ended up Very Simple... Walk the tree and call
setValue(getValue().trim)