xlst 2.0 seqential analysys of elements

R

Rolf Kemper

Dear ALL,

I have an xml containing an order of elements which is quite big (Mega
Bytes)
Example:
<root>
<e1 />
<e5 />
<e3 />
<e2 />
<e5 />
<e2 />
<e1 />
</root>

What I want to do is to look for a ceratin sequence of elements:
e.g. e5,e2 (e5 must be followed by e2)
e.g. e5,*,e2 (which left out e3)

In a matching template or foreach I have only the current element in
scope.
A variable used in that scope is re-defined in next match. Hence this
does not help.
How can this be solved somehow

Any hint is welcome
Rolf
 
J

Joe Kesselman

What I want to do is to look for a ceratin sequence of elements:

I'd start with the child, preceding-sibling, and/or following-sibling
axes and predicates -- most importantly, I suspect, positional predicates.


--
Joe Kesselman,
http://www.love-song-productions.com/people/keshlam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 
M

Martin Honnen

Rolf said:
Dear ALL,

I have an xml containing an order of elements which is quite big (Mega
Bytes)
Example:
<root>
<e1 />
<e5 />
<e3 />
<e2 />
<e5 />
<e2 />
<e1 />
</root>

What I want to do is to look for a ceratin sequence of elements:
e.g. e5,e2 (e5 must be followed by e2)
e.g. e5,*,e2 (which left out e3)

In a matching template or foreach I have only the current element in
scope.
A variable used in that scope is re-defined in next match. Hence this
does not help.
How can this be solved somehow

Doesn't
<xsl:template match="/">
<xsl:if test="root/e5[following-sibling::*[1][self::e2]]">
...
</xsl:if>
</xsl:template>
do the check for the first type of sequence you asked for?
The second would be
<xsl:if test="root/e5[following-sibling::*[1] and
following-sibling::*[2][self::e2]]">...</xsl:if>

Of course instead of an xsl:if check you could use such expressions in
an apply-templates or for-each, depending on what you want to do if you
find a sequence.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top