[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Inserting a separator only between non-empty strings

Subject: 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
 Inserting a separator only between non-empty strings
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.