Space only value in xsl:variable
Added by Adrian Bird 6 months 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 6 months 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 6 months 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 6 months ago
Saxonica Developer Community notifications@plan.io 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
Please register to reply