This is the mail archive of the
mailing list .
Re: alt. to for-each when there's only one
- From: "Thomas B. Passin" <tpassin at mitretek dot org>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 12 Feb 2002 10:04:39 -0500
- Subject: Re: [xsl] alt. to for-each when there's only one
- References: <firstname.lastname@example.org>
- Reply-to: xsl-list at lists dot mulberrytech dot com
> I've bee using <xsl:for-each select="Orders/RowId">
> to process all the RowId children of my one Orders
> But I've got a case where I know the xml returned
> to me will only contain one RowId child. Is using
> a for-each still the way to go in this case? Or is
> there something more direct and efficient?
You usually have a choice between xsl:for-each and xsl:apply-templates for
processing a series of elements. They aren't fully interchangeable, but
often you can arrange to use one or the other. There is no harm in using
xsl:for-each when there is only one element to loop over, but more than
likely, xsl:apply-templates will be able to do the job for you.
The prime situation where you want to use xsl:for-each instead of
xsl:apply-templates when there is only one element is when you need to
change the context, as for instance when you want a key to apply to xml
brought in from another source by means of document().
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list