This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XSTL - Help / Easy one!
- From: Mike Brown <mike at skew dot org>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 5 Feb 2002 19:56:04 -0700 (MST)
- Subject: Re: [xsl] XSTL - Help / Easy one!
- Reply-to: xsl-list at lists dot mulberrytech dot com
Ragan, Mitch wrote:
> How can I remove the "trailing coma" on this XSLT output
> with our using an "if" statement:
>
> XSLT:
> <xsl:template match="Portfolio/Stock">
> <xsl:apply-templates select="Symbol"/>,
> </xsl:template>
You're going to get 9 zillion answers, all variations of:
<xsl:template match="Portfolio/Stock">
<xsl:apply-templates select="Symbol"/>
<xsl:if test="position() != last()">,</xsl:if>
</xsl:template>
But they'll probably neglect to mention that you should do it
like this
<xsl:template match="/">
<xsl:apply-templates select="Portfolio/Stock"/>
</xsl:template>
<xsl:template match="Stock">
<xsl:apply-templates select="Symbol"/>
<xsl:if test="position() != last()">,</xsl:if>
</xsl:template>
so you can ensure that position() and last() work as expected,
returning numbers that are relative to the set of Stock elements
that have been selected for processing, rather than the set of
all children of the parent element or root node, as the built-in
templates would otherwise cause to be processed.
- Mike
____________________________________________________________________________
mike j. brown, fourthought.com | xml/xslt: http://skew.org/xml/
denver/boulder, colorado, usa | personal: http://hyperreal.org/~mike/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list