Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: David Carlisle <davidc@--------->
To:
Date: 2/1/2005 5:02:00 PM
<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
________________________________________________________________________


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent