Re: [xsl] recursive counter not incrementing

Subject: Re: [xsl] recursive counter not incrementing
From: Christopher Hansen <chansen1@xxxxxxxxx>
Date: Wed, 8 Dec 2004 20:28:09 -0500
David
Ultimately i am trying to check if the items in $s1 can also be found in $s2.  
For example - 
$s1 would consist of 2 items, $s1/item/Milk and $s1/item/Sugar
$s2 would consist of 10 different items, Milk and Sugar are among them.  
I've accomplished this using the for-each loop you suggested, however
i need a way to signal that ALL items have been found after the loop,
and not only some of them.

I'm thinking something like:

<xsl:for-each select="$s1/item[.=$s2/item]">
   <!--now, try to place the items that it found matches for, into a
nodeset and compare it to the original $s1 itemset.  If the results
from the for-each loop and the $s1 itemset contain the same items,
output COMPLETE MATCH-->
       
However, i'm not sure how to accomplish getting every matched item it
finds into a nodeset of some sort that i can use for a comparison
later on.  Any help would be appreciated...I'm a beginner and
frustration is setting in, but so far you guys have helped me a good
deal. Thanks.

Chris

On Wed, 8 Dec 2004 22:41:37 GMT, David Carlisle <davidc@xxxxxxxxx> wrote:
> 
> It's not clear why you are using recursion rather than just using
> postion() or count to get this number, but perhaps that's just because
> you have cut the example down, I didn't follow all the logic of your
> stylesheet but can comment on some lines:
> 
>                <xsl:with-param name="s1"
>                select="$s1/item[following-sibling]"/>
> 
> That selects all items that have a child called following-sibling so it
> will be empty, I don't know which nodes you mean to select here but
> perhaps
>   select="following-sibling::*"
> 
>      <xsl:for-each select="$s1/item">
>         <xsl:variable name="sub1" select="."/>
> 
>         <xsl:for-each select="$s2/item">
>           <xsl:if test="$sub1 = . ">
> 
> 
> This is rather strange, it loops through all pairs of items in s1
> and s1 but only does anything if the items are equal
> so you could just select those pairs with a single xpath:
>   <xs:for-each select="$s2/item[.=$s1/item]">
> 
> which is more compact to write and at least gives the system a chance of
> being a bit more efficient.
> 
> It seems that you want to use an integer counter as your main control
> and repeatedly pass the whole of yor set $s1 and keep accessing $s1[$i]
> this isn't the usual XSL way, normally you would just simply pass the
> current node as a parameter, and then move control to teh following
> sibling, without ever needing your integer position variable.
> 
> 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