RE: [xsl] append values to a String

Subject: RE: [xsl] append values to a String
From: "Wang, Dongzhi (ACF)" <DWang@xxxxxxxxxxx>
Date: Wed, 12 Feb 2003 11:47:51 -0500
Thanks so much, Brian and Jeni!  I was struggling to find out how I could
keep replacing the String, and I never thought it could be solved in couple
of lines like this...  

-----Original Message-----
From: Martinez, Brian [mailto:brian.martinez@xxxxxxxx]
Sent: Wednesday, February 12, 2003 11:20 AM
To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Subject: RE: [xsl] append values to a String 


> From: Wang, Dongzhi (ACF) [mailto:DWang@xxxxxxxxxxx]
> Sent: Wednesday, February 12, 2003 8:52 AM
> Subject: [xsl] append values to a String 
> 
> Hi,
> 
> I had a similar question to the one Stevenson just asked 
> about variable.  I
> know it's impossible to re-assign value to a variable in XSL, 
> that's why I
> don't know what to do in here.  
> 
> Here's the xml:
> 
> <Sample>
> 	<K1/>
> 	<K2>something</K2>
> 	<K3>something else</K3>
> 	<K4/>
> </Sample>
> 
> I'd like to loop through all the children nodes under 
> <Sample>, find those
> have non-empty value, and construct a String with all those 
> values append to
> each other with a "," delimiter in between them, i.e. the 
> result String
> should look like:  "something,something else,".  And I need 
> to assign this
> String to a variable since I need to use it elsewhere.

<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.

| brian martinez                              brian.martinez@xxxxxxxx |
| senior gui programmer                                  303.708.7248 |
| trip network, inc.                                 fax 303.790.9350 |
| 6436 s. racine cir.                             englewood, co 80111 |
| http://www.cheaptickets.com/                   http://www.trip.com/ |

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

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


Current Thread