[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to copy all child elements except specific one

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




<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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.