xsl-list
[Top] [All Lists]

RE: append values to a String

2003-02-12 13:57:51
Kudos to Jeni for an elegant and clear solution, as wonted.

In reply to Brian,

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of 
Martinez,
Brian
Sent: Wednesday, February 12, 2003 10:20 AM
To: 'xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com'
Subject: RE: [xsl] append values to a String 

...

<xsl:variable name="big-string">
  <xsl:for-each select="Sample/*">
    <xsl:if ". != ''">
      <xsl:value-of select="."/>
      <xsl:if "position() != last()">,</xsl:if>
    </xsl:if>
  </xsl:for-each>
</xsl:variable>

Note that if the last child node is empty you'll still get a 
trailing comma
in your string--I'm sure there's a way to fix that but I have 
a meeting to
go to . . .  ;-)

hth,
b.


Mr. Wang didn't ask for the final comma to be avoided, but
if we wanted that, how about

      <xsl:if test="following-sibling::*[string()]">,</xsl:if>

Maybe not the most efficient, but it works.

Alternatively, we could take a substring of the $big-string
result to avoid any final comma.

Lars


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>