xsl-list
[Top] [All Lists]

RE: xslt: Wrapping multiple elements in a parent element

2003-05-09 00:40:58


De : Steven Curry [mailto:scurry1(_at_)msn(_dot_)com]
I need to do an xml to xml transformation where I take 1 or 
more elements of 
a certain name (they are grouped together somewhere in the 
hierarchy) and 
wrap them in a new parent element.  The rest of the document 
should stay the 
same.  Any xslt suggestions?  I'm sure there is any easy 
solution but I 
haven't found it yet.

Hi Steve,

Use the identity transformation for all elements except the ones you're
interested. That is, 

<xsl:template match="myNode">
  <myNewParent>
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </myNewParent>
</xsl:template>

<xsl:template match="@*|node()" priority=">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

Cheers,
Dave.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list