Is there a simple way to strip padding, IE leading and/or trailing white space. EXSLT padding function seems to only create padding or trim strings to a certain length.
+1
A:
Would normalize-space() do the job for you? This will also reduce spaces inside the string, e.g.
" this string "
would become:
"this string"
If you really need a "trim" function, you can probably steal one from someone else who's already implemented it with normalizse-space()...
Matt Gibson
2010-09-08 13:27:05
Or one could use the replace function (http://www.w3.org/TR/xpath-functions/#func-replace). It should work more or less (i.e. it's untested) like this: `replace(string, '^\s*(.*?)\s*$', '')`.
musiKk
2010-09-08 13:38:33
A:
It isn't clear what is wanted -- what is "strip padding"?
If you meant the trim() function, then
The FXSL library provides a convenient trim
template function.
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="trim.xsl"/>
<xsl:output method="text"/>
<xsl:template match="/">
'<xsl:call-template name="trim">
<xsl:with-param name="pStr" select="string(/*)"/>
</xsl:call-template>'
</xsl:template>
</xsl:stylesheet>
when applied on this XML document:
<someText>
This is some text
</someText>
produces the wanted, correct result:
'This is some text'
Dimitre Novatchev
2010-09-08 13:43:25