This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Node Selection
- To: "Decarli, Jim" <Jim dot Decarli at fishersci dot com>
- Subject: Re: [xsl] Node Selection
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Fri, 15 Jun 2001 16:18:10 +0100
- CC: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <CEF9AB1E09C6D31183680001FA6864F80538616D@EXCHG-PDC-PLPGH>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Jim,
> I am using Xalan for xsl transformations. I have some xml with
> multiple <Activity> nodes in it for each part that is processed. The
> activity nodes are not sorted in any way in the xml. I want to
> select only the latest activity (by Date, Time) to process in the
> transform for my output to show the last activity scan on this part
> and ignore all other activity scans.
The easiest way to do this is to sort the Activity elements by their
Date and Time (in descending order), and then choose the first one
only to go on and process:
<xsl:template match="Part">
<xsl:for-each select="Activity">
<xsl:sort select="Date" order="descending" />
<xsl:sort select="Time" order="descending" />
<xsl:if test="position() = 1">
<xsl:apply-templates select="." />
</xsl:if>
</xsl:for-each>
</xsl:template>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list