[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Reordering elements

Subject: Re: Reordering elements
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Tue, 13 Jun 2006 23:23:19 +0200
story elements
Chad Chelius 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>?


It depends. I assume you have something like
 <Root>
  <Story>
    some content
  </Story>
  <Source>
    some source stuff
  </Source>
  <Story>
    some more content
  </Story>
  <Source>
    some more source stuff
  </Source>
 <Root>
with one and only one Source element following a Story element.

and you want this transformed into
 <Root>
  <Story>
    some content
    some source stuff
  </Story>
  <Story>
    some more content
    some more source stuff
  </Story>
 <Root>

Then the following should work:
  <xsl:template match="Story">
   <Story>
     <!-- first copy all original children of the Story element -->
     <xsl:copy-of select="node()"/>
     <!-- then copy all children of the following Source element -->
     <xsl:copy-of select="following-sibling::Source[1]/node()"/>
   </Story>
  </xsl:template>
  <!-- suppress Source elements -->
  <xsl:template match="Source"/>
You'll need to process the Root element, and you may want to apply
other methods in order to suppress processing the original Source
elements.
And beware: the code above is completely untested.

J.Pietschmann

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.