[xsl] Using deep-equal() to match sequences of children

Subject: [xsl] Using deep-equal() to match sequences of children
From: Yves Forkl <Y.Forkl@xxxxxx>
Date: Wed, 25 Jul 2007 16:08:31 +0200
In my input, I am using deep-equal() to detect specific children of some element by repeatedly scanning its children, and taking an appropriate action if one is found. The children may appear in any order and are checked against the children of a sequence of "known instances".

Now I discovered that I also need to match certain sequences of children (i.e. subsequences) at once, not only individual children within the sequence. I am kindly asking you for help with this problem, which I hope to solve using deep-equal(), too.

Let us assume that my list of known "things" that I am looking for (unordered sequences and single instances of elements) reads:

1) <a/>

2) <b/>

3) <a/><b/>

Wrapping each of them into a container (in order to provide a single node for the comparison) and adding a root element gives:


(Trying to find the "longest" match first...)

My input may possibly contain these known "things" in any order within its INPUT instance, as well as additional children. So when reading in:


we should find a match for <a/><b/>.

I would like to tackle this problem by extending the way in which I am already comparing single children, working my way through <my_list> and testing for each $my_item if:

some $child in INPUT/* satisfies deep-equal($child, $my_item)

Now I am stuck with these questions:

- Supposing I should first put my INPUT children in some order to get rid of permutations, which is best way to do this in XSLT 2?

- Looking for matching subsequences within an ordered sequence should equal getting the length of the current $my_item, take that number of children from INPUT starting with its first child, wrap them into a container to create the single-rooted tree needed for comparison, and finally apply deep-equal(). Then repeat all this for any following child within INPUT. If that is a sound approach, how to code that in XSLT 2?

- How can I avoid prefix-type matches, i.e. if we already matched <a/><b/>, how to stop <a/> and <b/> from matching?

Are there any XSLT-experienced set theoreticians on the list that could shed some light? :-)


P.S.: For the curious, this message is about the same problem as that message here to which nobody answered:

So I thought reformulating might make the topic more appealing... :-)

Current Thread