[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xsl-list
Subject:    Re: [xsl] How to compare two sequences, where order matters and length matters?
From:       "Michael Kay mike () saxonica ! com" <xsl-list-service () lists ! mulberrytech ! com>
Date:       2017-11-21 23:42:40
Message-ID: 20171121184214.72573 () lists ! mulberrytech ! com
[Download RAW message or body]

The deep-equal() function MIGHT meet your requirement. But your requirement isn't \
described in enough detail to be sure (you've only specified it by showing examples \
of some operands that are equal and some that aren't). For a full specification you \
need to say how to handle comments, whitespace, in-scope namespaces, base URI, schema \
type annotations, etc etc etc.

Michael Kay
Saxonica

> On 21 Nov 2017, at 23:21, Costello, Roger L. costello@mitre.org \
> <xsl-list-service@lists.mulberrytech.com> wrote: 
> Hi Folks,
> 
> Consider this XML:
> 
> <sequences>
> <sequence/>
> <sequence>
> <item>A</item>
> </sequence>
> <sequence>
> <item>B</item>
> </sequence>
> <sequence>
> <item>A</item>
> <item>A</item>
> </sequence>
> <sequence>
> <item>A</item>
> <item>B</item>
> </sequence>
> <sequence>
> <item>B</item>
> <item>A</item>
> </sequence>
> <sequence>
> <item>B</item>
> <item>B</item>
> </sequence>
> </sequences>
> 
> Suppose that $item has this value:
> 
> <item>A</item>
> 
> And suppose the root element, <sequences>, is the context node.
> 
> Then, this evaluates to true (thanks David):
> 
> sequence[2] = (sequence[1], $item)
> 
> Unfortunately, this also evaluates to true:
> 
> sequence[4] = (sequence[1], $item)
> 
> sequence[4] is this:
> 
> <sequence>
> <item>A</item>
> <item>A</item>
> </sequence>
> 
> And this also evaluates to true:
> 
> sequence[5] = (sequence[1], $item)
> 
> sequence[5] is this:
> 
> <sequence>
> <item>B</item>
> <item>A</item>
> </sequence>
> 
> Eek!
> 
> I don't want that. I only want these two sequences to match: sequence[2] and \
> (sequence[1], $item). 
> For this comparison:
> 
> Blah/item *compare-operator* (Bar/item, $item)
> 
> It should only return true if:
> 
> 1. The number of <item> elements are the same on the left and right side of \
> compare-operator. 
> 2. The value of item[1] of the left sequence equals the value of item[1] of the \
> right sequence. The value of item[2] of the left sequence equals the value of \
> item[2] of the right sequence. Etc.
> 
> In other words, in the comparison the order of the items in the left and right \
> sequences matters and the number of the items in the left and right sequences \
> matter.  
> What XPath expression will do such a comparison? 
> 
> Note: I'd like the XPath expression to *not* use a for-each loop.
> 
> /Roger 
> 
> 
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/651070
or by email: xsl-list-unsub@lists.mulberrytech.com
--~--


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic