xsl-list
[Top] [All Lists]

RE: recursive counter not incrementing

2004-12-09 03:05:23
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.

In predicate logic that's

 for each ITEM1 in $s1
   there exists ITEM2 in $s2
     such that ITEM1 = ITEM2

or in XPath 2:

 every $I1 in $s1 satisfies 
    some $I2 in $s2 satisfies
       $I1 eq $I2

In XPath 1 the equivalent of "some" can be achieved with

$s2[predicate]

and the equivalent of "every" can be achieved with

not($s1[not(predicate)])

but without range variables, you can't combine the two conditions into a
single expression.

However, there's another tool in the kitbag: the "existential equals". The
"=" operator, and its friends, compare two sets, rather than just
singletons. A=B is true if some pair of items from A and B are equal

So you can write

not($s1[not(item = $s2/item)])

which I think tests the condition you are looking for.

Michael Kay
http://www.saxonica.com/

  
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(_at_)nag(_dot_)co(_dot_)uk> 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

______________________________________________________________
__________




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--