This is the mail archive of the mailing list .

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: alt. to for-each when there's only one


> I've bee using <xsl:for-each select="Orders/RowId">
> to process all the RowId children of my one Orders
> node.
> 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().


Tom P

 XSL-List info and archive:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]