1

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.

spyderman4g63
  • 4,087
  • 4
  • 22
  • 31
  • 1
    What 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 Answers3

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
  • 1
    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 Sep 08 '10 at 13:38
1

Try normalize-space

<xsl:value-of select='normalize-space(string)'/>
StuartLC
  • 104,537
  • 17
  • 209
  • 285
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