## [xsl] How to compare two sequences, where order matters and length matters?

 Subject: [xsl] How to compare two sequences, where order matters and length matters? From: "Costello, Roger L. costello@xxxxxxxxx" Date: Tue, 21 Nov 2017 23:21:08 -0000
```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

```