AP123
AP123

Reputation: 57

how to store 2 spaces in xslt variable

<xsl:variable name="asteriskSpaceSpaceAsterisk" select="'*  *'"/>

<xsl:value-of select="$asteriskSpaceSpaceAsterisk"/>

EXPECTED OUTPUT
*  *
ACTUAL OUTPUT
* *

Question 1) The above line stores only 1 space instead of 2. How do i store 2 spaces

Question 2)

<xsl:when test="starts-with($strippedString,'*  *')">
   <xsl:value-of select="substring($strippedString,5,string-length($strippedString))"/>
</xsl:when>

I am not getting a match even if the string starts with a sub-string that contains 2 spaces between asterisks. What do I have to do to get a match?

I am using xslt 1.0

Upvotes: 0

Views: 671

Answers (1)

Valdi_Bo
Valdi_Bo

Reputation: 30971

If you create a text to be rendered by a browser, you can define your variable as:

<xsl:variable name="asteriskSpaceSpaceAsterisk" select="'*&#160;&#160;*'"/>

This way the string contains 2 unbreakable spaces, which will not be "squashed" to a single space by a browser.

Another remark: In substring function, the third argument gives the length of the output string, not the "stop position".

But if you want to extract a substring from some point, up to the end, just omit this parameter.

Upvotes: 2

Related Questions