RE: [xsl] How to copy all child elements except specific one?

Subject: RE: [xsl] How to copy all child elements except specific one?
From: "Morris, Chris" <ChrisM@xxxxxxxxxxxxxxxx>
Date: Tue, 16 Jan 2001 13:58:58 -0600
Okay - the following xsl does what I need. Is it Good®, or can it be
improved upon?

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

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

<xsl:template match="Level3">
  <xsl:element name="Level3">
    <xsl:copy-of select="*[not(name()='ChildElementToChange')]" />
    <xsl:variable name="L3Attr" select="@L3Attr" />
    <xsl:for-each select="ChildElementToChange">
      <xsl:call-template name="ChangeChildElement">
        <xsl:with-param name="L3Attr"><xsl:value-of select="$L3Attr"
/></xsl:with-param>
      </xsl:call-template>
    </xsl:for-each>
   </xsl:element>
</xsl:template>

<xsl:template name="ChangeChildElement">
  <xsl:param name="L3Attr" />
  <xsl:element name="ChildElementToChange">
    <xsl:element name="NewElement">
      <xsl:attribute name="L3Attr"><xsl:value-of select="$L3Attr"
/></xsl:attribute>
      <xsl:attribute name="OldValue"><xsl:value-of select="@OldValue"
/></xsl:attribute>
      <xsl:attribute name="NewValue"><xsl:value-of select="@NewValue"
/></xsl:attribute>
    </xsl:element>
  </xsl:element>
</xsl:template>

</xsl:stylesheet>

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


Current Thread