| 
 
Subject: Re: [xsl] Node Position() always equals 1 From: Cynthia DeLaria <cdelaria@xxxxxxxxxxxxx> Date: Tue, 1 Feb 2005 13:40:27 -0800 (PST)  | 
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@xxxxxxxxx>
Sent: Feb 1, 2005 9:01 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
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
________________________________________________________________________
| Current Thread | 
|---|
  | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] Node Position() always eq, David Carlisle | Thread | RE: [xsl] Can you break one node tr, Wilde Rebecca L SSgt | 
| RE: [xsl] xsl:element name AVT, Michael Kay | Date | Re: [xsl] Optimization Question, Kevin Jones | 
| Month |