[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Node Position() always equals 1

Subject: Re: Node Position() always equals 1
From: Cynthia DeLaria <cdelaria@xxxxxxxxxxxxx>
Date: Tue, 1 Feb 2005 13:40:27 -0800 (PST)
xsl node position
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:  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.