Re: [xsl] reversing or swapping nested node hierarchy

Subject: Re: [xsl] reversing or swapping nested node hierarchy
From: Chris Capon <abyss@xxxxxxxxxxx>
Date: Mon, 20 Mar 2006 16:06:11 -0500
G. Ken Holman wrote:

>I hope the code below helps.  You don't say what you want done with 
>attributes, so I didn't do anything with them myself.
>
>. . . . . . . . . Ken
>  
>
Thanks for your reply.  My example may have been too simple for what I'm
trying to do.  I should have specified that <a>, <b>, etc need to be
transformed, so a simple node copy would not be enough.

What I'm essentially looking for is a way to change the node hierarchy
during transformation.

So, if my document were:

<root>
  <a name="alpha">
    <b tag="beta" />
  </a>
</root>

and my templates were:

<template match="a">
  <aa>
    <copy-of select="@name" />
  </aa>
</template>
<template match="b">
  <bb>
    <copy-of select="@tag" />
  </bb>
</template>

would there be a way to produce this output:

<doc>
  <bb tag="beta">
    <aa name="alpha">
  </bb>
</doc>

where the node hierarchy  a/b  has been reversed to become  bb/aa  ?

The optimal solution would leave the "b" template generic so the element
could be included under other elements like  <a>, <c> and <d> in your
example.

Thanks, Chris.

Current Thread