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

Subject: Re: [xsl] How to copy all child elements except specific one?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 16 Jan 2001 21:39:47 GMT




<xsl:template match="Level3">

  <xsl:element name="Level3">
simpler to write <Level3>

    <xsl:copy-of select="*[not(name()='ChildElementToChange')]" />

better to do *[not(self::ChildElementToChange)]

    <xsl:variable name="L3Attr" select="@L3Attr" />

No need to use a variable here, just means you access with $ instead of
../@

    <xsl:for-each select="ChildElementToChange">
      <xsl:call-template name="ChangeChildElement">
It would probably have been simpler to just use
<xsl:apply-templates select="ChildElementToChange"/>
rather than use a named template in for-each, but if you are using a
named template then

        <xsl:with-param name="L3Attr"><xsl:value-of select="$L3Attr"
/></xsl:with-param>
This could more simply be expressed as
         <xsl:with-param name="L3Attr" select="../@L3Attr"/>
but you don't need a parameter at all as the named template has access
this to this data as @L3Attr
     </xsl:call-template>
    </xsl:for-each>
   </xsl:element>
</xsl:template>




<xsl:template name="ChangeChildElement">
as noted above, it would probably have been simpler
to have <xsl:template match="ChildElementtoChange">

  <xsl:param name="L3Attr" />
and you don't need this param.

  <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>

the above lines could be written as
<ChildElementToChange>
<NewElement>
<xsl:copy-of select="@OldValue|@NewValue|../@L3Attr"/>
</NewElement>
</ChildElementToChange>


</xsl:template>

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

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


Current Thread