XML technologies / XSLT / Introduction to XSLT 2.0 / Getting started with XSLT and XPath / A comparison: expression vs. instruction / The separator attribute of xsl:value-of

(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 1.)

Another feature of the example you may have noticed comes from the behavior of xsl:value-of with sequences, not from the sequence itself.

In the previous output, an extra space appears between the string values of processed items. This may seem natural and is useful, but it would be equally logical for xsl:value-of simply to concatenate both string values directly: ha haha ha instead of ha ha ha ha.

The reason is an attribute not yet mentioned, separator whose default takes effect here. It controls the string inserted between individual items’ string values. If omitted, a single space is used as the separator. The code therefore effectively means:

<xsl:value-of select="(lachen, lachen)" separator=" "/>

produces: ha ha ha ha

A different character can of course be used:

<xsl:value-of select="(lachen, lachen)" separator="+"/>

produces: ha ha+ha ha

Or any string of several characters:

<xsl:value-of select="(lachen, lachen)" separator=", hoho, "/>

produces: ha ha, hoho, ha ha

Explicitly setting separator="" as the empty separator concatenates the individual string values directly.

The separator attribute of xsl:value-of specifies a character or string to separate items’ string values. The default is one space. No separator is added after the final value.

   

back to top