This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Question reqarding display the content pending on the number of elements
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "ªL ¤lªä" <minikittygo at hotmail dot com>
- Cc: XSL-List at lists dot mulberrytech dot com
- Date: Wed, 23 Jan 2002 16:38:39 +0000
- Subject: Re: [xsl] Question reqarding display the content pending on the number of elements
- Organization: Jeni Tennison Consulting Ltd
- References: <F197NY1SWoBDyseVwrb00023a66@hotmail.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Kit,
> the question is, how do i insert the comma at the end of each
> children element using xsl stylesheet BUT not adding a comma for the
> last children (e.g. wayne for the smith and Jay)?
Iterate over the children elements, and add a comma for each of them,
unless they are the last, which you can work out by looking at their
position:
<xsl:for-each select="children">
<xsl:value-of select="." />
<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>
[Or in XSLT 2.0, simply:
<xsl:value-of select="children" separator=", " />]
> in addition, is there a way to use xsl:if statment that will give a
> condition that states "if the number of element (children in the
> above example) are more than 1"
Sure:
<xsl:if test="count(children) > 1">...</xsl:if>
Or if you prefer, you can just test whether there's a second children
element:
<xsl:if test="children[2]">...</xsl:if>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list