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

Re: Inserting a separator only between non-empty strin

Subject: Re: Inserting a separator only between non-empty strings (XSLT 2)
From: mozer <xmlizer@xxxxxxxxx>
Date: Fri, 18 May 2007 12:12:57 +0200
Re:  Inserting a separator only between non-empty strin
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

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-2013 All Rights Reserved.