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

RE: Moving an element to a new location in the Result

Subject: RE: Moving an element to a new location in the Result-tree
From: david_n_bertoni@xxxxxxxxxx
Date: Wed, 7 Sep 2005 18:38:25 -0700
stylesheet move element
> I want to move the former "b1" elements down the tree and re-name them
> (all) along the way, yet maintain the actual data they contain ("XYZ1",
> etc.).  The main thing is to move them down there, not re-name them. 

Remember that you are not "moving" anything -- you're creating a whole new 
result tree.  That may seem to be a trivial detail, but it's really a 
fundamental concept you need to remember always.

If the whitespace-only text nodes are not significant, then the following 
stylesheet will do what I think you want:

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

<xsl:output method="xml" indent="yes"/>

<xsl:strip-space elements="*"/>

<xsl:template match="@* | node()">
     <xsl:apply-templates select="@* | node()"/>
<xsl:template match="b1">
     <xsl:apply-templates select="@* | node()"/>
<xsl:template match="document1">
    <xsl:apply-templates select="*[not(self::b1)]"/>
    <xsl:apply-templates select="b1"/>


If you really need to preserve whitespace-only text nodes, things get a 
bit trickier.


Current Thread


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.
First Name
Last Name
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.