xsl-list
[Top] [All Lists]

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

2017-11-21 17:27:46
deep-equal?

On 21 November 2017 at 17:21, Costello, Roger L. costello(_at_)mitre(_dot_)org
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)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/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>