Recursive XSLT, part 2

Posted by Eric on Stack Overflow See other posts from Stack Overflow or by Eric
Published on 2010-05-25T19:28:56Z Indexed on 2010/05/25 19:31 UTC
Read the original article Hit count: 376

Filed under:
|
|
|

Ok, following on from my question here.

Lets say my pages are now like this:

A.xml:

<page>
    <header>Page A</header>
    <content-a>Random content for page A</content-a>
    <content-b>More of page A's content</content-b>
    <content-c>More of page A's content</content-c>
    <!-- This doesn't keep going: there are a predefined number of sections -->
</page>

B.xml:

<page include="A.xml">
    <header>Page B</header>
    <content-a>Random content for page B</content-a>
    <content-b>More of page B's content</content-b>
    <content-c>More of page B's content</content-c>
</page>

C.xml:

<page include="B.xml">
    <header>Page C</header>
    <content-a>Random content for page C</content-a>
    <content-b>More of page C's content</content-b>
    <content-c>More of page C's content</content-c>
</page>

After the transform (on C.xml), I'd like to end up with this:

<h1>Page C</h1>
<div>
 <p>Random content for page C</p>
 <p>Random content for page B</p>
 <p>Random content for page A</p>
</div>
<div>
 <p>More of page C's content</p>
 <p>More of page B's content</p>
 <p>More of page A's content</p>
</div>
<div>
 <p>Yet more of page C's content</p>
 <p>Yet more of page B's content</p>
 <p>Yet more of page A's content</p>
</div>

I know that I can use document(@include) to include another document. However, the recursion is a bit beyond me.

How would I go about writing such a transform?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xslt