XML traversal in level-order (breadth-first) with XSLT

C

Christian Rühl

I suspect I know what causes your problem. More on that

Yes, you did! :)
Uh, no, not really. First of all, this template would be
invoked when you are processing top element in your 'tree'
document. And your second template application would start
processing from the root node of 'tree' document again,
*whammo* infinite recursion. Replace select="$treeDoc" with
select="*" (you want to process all the children of top
element here, not the whole document once again).

But wait, it gets worse. Your 'archive' document contains
contains a top element as well. That element would match
this very same template, *whammo* infinite recursion.
Basically, there are two ways around that:

Uff, I didn't expect that there were two infinite recursions... That's
why I always got the same error message no matter what I changed to
get rid of "the infinite one".
1. Use modes. You can use mode attributes on
xsl:apply-templates and xsl:template elements to
manually specify different rules for superficially
similar scenarios (such as 'top' element having
different semantics in different documents).

2. Change your template so that it matches 'top' element
in 'tree' document, but not in 'archive' document. In
your sample documents this is trivial:

<xsl:template match="top[product]">

This only matches top elements that have product
element children.

Aaaaaaah, now things get more clear to me!
I strongly recommend taking a very small XML document, a
small transformation, and doing the transformation on
paper. This is going to take half an hour to figure out,
but once you go through this (and once your results match
those that actual XSLT processors produce), you'll have a
much more clear mental picture of how XSLT stylesheets are
processed, and believe me, this is going to be immensely
helpful.

I already played it through on paper, but I didn't know where the
infinite recursions came from. As said before, I didn't even realize
that there were two of them.
Well, I guess I need a little more experience... :)

I'll be knocking off now, but I will try a new version tomorrow.

Once again, thank you! You're a great help! Have a good one!
 
J

Joseph Kesselman

Christian said:
I already played it through on paper, but I didn't know where the
infinite recursions came from. As said before, I didn't even realize
that there were two of them.
Well, I guess I need a little more experience... :)

The <xsl:message> directive can be useful as a debugging aid, to show
you what your stylesheet is actually doing.

Another possibly useful tool: my article on styling stylesheets on
DeveloperWorks (http://www.ibm.com/xml) shows, step by step, the
creation of a stylesheet which adds debugging information to other
stylesheets.

I think there may be an XSLT debugging tool available for Eclipse, using
the Xylem processor... I know a prototype was written, but I'm not sure
how far they got on it or whether it was made generally available.
 
C

Christian Rühl

The said:
you what your stylesheet is actually doing.

Good to know. :)
I just looked up a few examples. Thanks!
Another possibly useful tool: my article on styling stylesheets on
DeveloperWorks (http://www.ibm.com/xml) shows, step by step, the
creation of a stylesheet which adds debugging information to other
stylesheets.

Nice work! I just printed that one.
Thanks a lot!
 

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,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top