Yes, I see that now... The for-each was a reduntant statement, because the
apply-templates was already grabbing all matching nodes... This has been
haunting me for a couple of weeks now... I have a much better understanding of
apply-templates and for-each now too...
Thank you so much, David. :)
Cynthia
-----Original Message-----
From: David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
Sent: Feb 1, 2005 9:01 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Node Position() always equals 1
<xsl:template match="offer">
<xsl:for-each select=".">
. selects exactkly one node so the current node list has one node and
position()=last()=1 here.
You probably just want to remove the for-each, it isn't doing anything
(except changing the value pf position().
Actually you probably shopuld get rid of your count variable as well.
You have
<xsl:variable name="count"><xsl:value-of
select="count(template/spec_off/offer[./@*[local-name()=$version]='true'])"
/></xsl:variable>
which means that $count is a result tree fragment with a root node and a
text node with a string that is the decimal expansion of the number of
nodes.
If you instead went
<xsl:variable name="count"
select="count(template/spec_off/offer[./@*[local-name()=$version]='true'])" />
$count would be the number of nodes, stored as a number. this is much
more efficient to store.
Howver in both cases the system has to search all teh documentto count
those nodes, then later when you test if $count is bigger than 1 it has
to go and find them again. So better (most likely) would be to make the
variable store the nodes themselves.
<xsl:variable name="count"
select="template/spec_off/offer[./@*[local-name()=$version]='true'])"
/>
Now instead of
<xsl:if test="$count > 1">
you can just test if that node set has any nodes:
<xsl:if test="$count">
and instead of
<xsl:apply-templates
select="template/spec_off/offer[./@*[local-name()=$version]='true'][position()
1]" />
you can just do
<xsl:apply-templates select="$count[position() > 1]"/>
(note that $count[position() > 1] latter is equivalent to
(template/spec_off/offer[./@*[local-name()=$version]='true'])[position() > 1]
but that is the same as you have as your offer elements are all
siblings.
David
________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--