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"
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: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 name="OldValue"><xsl:value-of select="@OldValue"
      <xsl:attribute name="NewValue"><xsl:value-of select="@NewValue"

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



This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit

 XSL-List info and archive:

Current Thread