xslt:value-of eats my white space?
This is an open discussion with 9 replies, filed under XSLT.
Search
You could concatenate them together.
<xsl:value-of select="concat(voornaam, ' ', tussenvoegsel, ' ', achternaam)" />
Take @nick's advice, it's best.
But if you ever want to be sure your white spaces appear in any situation, output them with  
or <xsl:text> </xsl:text>
Great, thanks a lot! I did find something about whitespace-preserve but couldn't get it working. The concat solution does work though and it makes my xsl statements shorter as well :)
@frankel: the problem with Nick's solution is that you will now get 2 whitespaces if there is no tussenvoegsel
, which is quite common in dutch names.
I would recommend that you check if tussenvoegsel is set, and change the value-of accordingly:
<xsl:choose> <xsl:when test="tussenvoegsel=''"><xsl:value-of select="concat(voornaam, ' ', achternaam)" /></xsl:when> <xsl:otherwise><xsl:value-of select="concat(voornaam, ' ', tussenvoegsel, ' ', achternaam)" /></xsl:otherwise> </xsl:choose>
Although @remie is right, I wouldn't mind too much of it, since 2 (or more) spaces in your HTML code would always be rendered as one space. Unless you have the name in a <pre>
or something...
I know... it's not strictly correct, but it keeps your XSL a bit tidier ;-)
Yep, I don't bother checking it because HTML won't care. But thanks for the suggestion :)
Or for purists it's cleaner and shorter to revert back from double spaces than using a conditional:
<xsl:value-of select="normalize-space(concat(voornaam, ' ', tussenvoegsel, ' ', achternaam))" />
That's exactly why everyone hates XSLT. Making simple things so ridiculously ugly and complicated.
Create an account or sign in to comment.
I have the following code in an html element:
However, the white space between is removed by XSLT. How can I prevent this? Note that sometimes the middle "value-of" returns an empty string, so I don't want to use