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.
Asked
Active
Viewed 257 times
1
-
1What is "strip-padding"? please, edit your question and give a concrete example of what you want! – Dimitre Novatchev Sep 08 '10 at 13:22
-
About white space handling there is more than one scenario... See http://stackoverflow.com/questions/184431/converting-xml-to-plain-text-using-xslt-how-should-i-ignore-handle-whitespace/185048#185048 – Sep 08 '10 at 13:35
3 Answers
1
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
- 37,886
- 9
- 99
- 128
-
1Or 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 Sep 08 '10 at 13:38
0
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
- 240,661
- 26
- 293
- 431