[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to compare two sequences, where order matters
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@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|