Project

Profile

Help

Space only value in xsl:variable

Added by Adrian Bird 27 days ago

I had a problem with substring() not extracting data from a xsl:variable that only contains spaces. After some investigation I discovered that a space only value in a xsl:variable sequence constructor is treated as an empty sequence. It was ok if I put the spaces within a xsl:text element in the variable.

<xsl:variable name="spaces01">    </xsl:variable> - treated as empty and displayed as an empty string. string-length() gives 0.
<xsl:variable name="spaces02"><xsl:text>    </xsl:text></xsl:variable> - ok, displayed as 4 spaces

Is there something I haven't read about space only sequence constructors that is responsible for this result?

Adrian


Replies (4)

Please register to reply

Space only value in xsl:variable - Added by Norm Tovey-Walsh 27 days ago

Is there something I haven't read about space only sequence constructors that is responsible for this result?

The relevant section is 4.3 Stripping Whitespace from the Stylesheet.

https://www.w3.org/TR/xslt-30/#stylesheet-stripping

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

RE: Space only value in xsl:variable - Added by Michael Kay 26 days ago

You can also use <xsl:variable name="x" select=" "/>. Generally for creating an atomic-valued variable, the select attribute is to be preferred.

RE: Space only value in xsl:variable - Added by Norm Tovey-Walsh 26 days ago

Saxonica Developer Community writes:

You can also use <xsl:variable name="x" select=" "/>. Generally for creating an atomic-valued variable, the select attribute is to be preferred.

I think Mike meant <xsl:variable name="x" select="' '"/>. You need to quote the string inside the select expression.

Be seeing you,
norm

--
Norm Tovey-Walsh
Saxonica

    (1-4/4)

    Please register to reply