xsl-list
[Top] [All Lists]

Re: concating strings in a loop

2004-02-10 07:34:17
Andrew Welch wrote:

hi!
i want to display a list of persons "comma-seperarted" on my pdf-file. how can i concate those person-names seperated with a "," but in that way, that after the last name is no ",".
i did it like this

<xsl:for-each select="person">
<xsl:value-of select="name" />
,<fo:inline color="white">.</fo:inline>
</xsl:for-each>
-> the output for example is: mike, john,
-> i want to have: mike, john
how can i concate the strings and substring it, so that the last comma will be removed

If your date looks like this:

<person>
 <name>mike</name>
</person>
<person>
 <name>john</name>
</person>

The instruction <xsl:for-each select="person"> will select a list of 2
nodes to process.  The function position() will give you the position of
the node you are currently processing in the list, and last() will give
you the position of node that's last in the list.  So, you only want to
output a comma if the position of the node you are processing is not the
last one:

<xsl:if test="position() != last()">, </xsl:if>


cheers
andrew

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

thank u - it works perfectly :)

--
Herwig Posedu

unycom Information Technology Services GmbH
Schmiedlstrasse 1/III
A-8042 Graz

Tel: ++43/316/818828-19
Fax: ++43/316/818828-38

herwig(_dot_)posedu(_at_)unycom(_dot_)com
www.unycom.com




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



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