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: mozer <xmlizer@xxxxxxxxx>
Date: Fri, 18 May 2007 12:12:57 +0200
and what about that ?

<xsl:variable name="concat">
<xsl:sequence>
 <xsl:value-of select="$a"/>
 <xsl:value-of select="$b"/>
 <xsl:value-of select="$c"/>
</xsl:sequence>
</xsl:variable>
<xsl:value-of separator="|" select="$concat[string-length(.) gt 0]"/>


Xmlizer


On 5/18/07, Yves Forkl <Y.Forkl@xxxxxx> wrote:
Hi,

I am kindly asking for help with the following problem. It looks like a
FAQ, but I couldn't find it in Dave Pawson's XSLT 2 FAQ section.

I am declaring 3 variables named a, b, c which must receive their values
not from the "select" attribute of xsl:variable, but from its element
contents which contain each zero, one or more instances of xsl:text,
xsl:value-of or xsl:sequence. All 3 variables are meant to convey
strings only - but I suppose, as a consequence of the way they are
declared, they actually carry text nodes.

Which is the easiest way to join these 3 values into the value of a new
variable named result (just a string), given that only those values
which evaluate to non-empty strings should be separated by "|"?

Do I need explicit testing on each value for the empty string or can I
use a more concise technique?

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. 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