Re: [xsl] Reordering elements

Subject: Re: [xsl] Reordering elements
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 14 Jun 2006 17:38:39 +0530
I assume, your XML is something like this:

<Root>
      <Story>
        xxx
      </Story>
      <Source>
        yyy
      </Source>
</Root>

I think a stylesheet like this should work:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<!-- identity template; copies everything -->
<xsl:template match="node() | @*">
 <xsl:copy>
   <xsl:apply-templates select="node() | @*" />
 </xsl:copy>
</xsl:template>

<xsl:template match="Story">
 <xsl:copy>
   <xsl:copy-of select="@*" />
   <xsl:apply-templates />
   <xsl:copy-of select="following-sibling::Source/node()" />
 </xsl:copy>
</xsl:template>

<xsl:template match="Source" />

</xsl:stylesheet>

In this stylesheet, the identity template has been modified for the
conditions you have specified.

Regards,
Mukul

On 6/14/06, Chad Chelius <cchelius@xxxxxxxxxxxxxxx> wrote:

In a situation where my XML file looks like this:


<Root>
       <Story>
       <Source>
</Root>

How would I move the <Source> element so that and it's children are
now a child of <Story>?

Current Thread