[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Inserting a separator only between non-empty strings (XSLT 2)


Subject: RE: [xsl] Inserting a separator only between non-empty strings (XSLT 2)
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 18 May 2007 11:19:35 +0100

> I tried
> 
> <xsl:variable name="result">
>    <xsl:value-of separator="|">
>      <xsl:value-of select="$a"/>
>      <xsl:value-of select="$b"/>
>      <xsl:value-of select="$c"/>
>    </xsl:value-of>
> </xsl:variable>
> 
> but this does never insert a separator.

That's because of the rules for construction of simple content

http://www.w3.org/TR/xslt20/#constructing-simple-content

which say that adjacent text nodes are concatenated in step 2, before
atomization and insertion of separators. (This is necesary so that
instructions like xsl:attribute work the way they did in XSLT 1.0).

Suggestion:

<xsl:variable name="result" 
  select="string-join((string($a), string($b), string($c))[.], '|')"/>

Michael Kay
http://www.saxonica.com/


 Replacing 
> xsl:value-of with xsl:sequence for the variable references 
> always inserts the separator, even near empty strings which 
> is what I want to avoid.
> 
>    Yves


Current Thread
Keywords