xsl-list
[Top] [All Lists]

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

2005-09-07 18:38:25
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"; 
version="1.0">

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

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

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

</xsl:stylesheet>

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

Dave

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--