XSL Strip Padding
Is there a simple way to strip padding, IE leading and/or trailing white space.开发者_Go百科 EXSLT padding function seems to only create padding or trim strings to a certain length.
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()...
Try normalize-space
<xsl:value-of select='normalize-space(string)'/>
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'
精彩评论