Bandwidth only

This item:

 <comments>  comments
go here
</comments>

How can I separate what can be several leading space characters. I cannot use normalized space because I need to keep new lines, etc. XSLT 2.0 is fine.

+5
source share
2 answers

Use function replace():

replace($input,'^ +','')

It processes leading leading space characters only up to the first non-space. If you want to remove all leading space characters (i.e. Space, nl, cr, tab) before the first non-space, use:

replace($input,'^\s+','')
+4
source

In XPath 1.0 (also means XSLT 1.0):

substring($input, 
          string-length(
                        substring-before($input, 
                                         substring(translate($input, ' ', ''), 
                                                   1,
                                                   1)
                                         )
                       ) +1
          )

XSLT transformation wrapped :

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

 <xsl:variable name="input"
   select="string(/*/text())"/>

 <xsl:template match="/">
   '<xsl:value-of select=
   "substring($input,
              string-length(
                            substring-before($input,
                            substring(translate($input, ' ', ''),
                                      1,
                                      1)
                                             )
                            ) +1
              )
   "/>'
 </xsl:template>
</xsl:stylesheet>

, XML-:

<t>    XXX   YYY Z</t>

, :

   'XXX   YYY Z'
+4

All Articles