xsl-list
[Top] [All Lists]

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

2007-05-18 03:19:59

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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--