Re: [xsl] Node Position() always equals 1

Subject: Re: [xsl] Node Position() always equals 1
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 1 Feb 2005 17:01:59 GMT
<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() &gt; 1]" />

you can just do
   <xsl:apply-templates select="$count[position() &gt; 1]"/>

(note that $count[position() &gt; 1] latter is equivalent to
  (template/spec_off/offer[./@*[local-name()=$version]='true'])[position() &gt; 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