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

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


Subject: [xsl] Inserting a separator only between non-empty strings (XSLT 2)
From: Yves Forkl <Y.Forkl@xxxxxx>
Date: Fri, 18 May 2007 11:55:18 +0200

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
Keywords