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

Re: Newbie : conditional node move

Subject: Re: Newbie : conditional node move
From: Gavin Corfield <gavin@xxxxxxxxxxxxxxxxxx>
Date: Wed, 16 May 2001 17:30:30 +0800
move to another node xsl
Godefroid Chapelle wrote:
> 
> Hi all,
> 
> A question about a problem I tried to solve the whole yesterday evening...
> 
> I could not find enough information or apply it correctly even in Michael Kay's
> book.
> 
> I have the following two cases:
> 
> 1)
> input
> 
> <AAA>
>   <BBB>bbb</BBB>
>   <CCC>ccc</CCC>
>   <DDD>ddd</DDD>
>   <EEE>eee</EEE>
> </AAA>
> 
> wished output
> 
> <AAA>
>   <DDD>
>    <XXX>bbb</XXX>
>     ddd</DDD>
>   <EEE>eee</EEE>
> </AAA>
> 
> 2)
> input
> 
> <AAA>
>   <BBB>zzz</BBB>
>   <CCC>ccc</CCC>
>   <DDD>ddd</DDD>
>   <EEE>eee</EEE>
> </AAA>
> 
> output
> 
> <AAA>
>   <DDD>ddd</DDD>
>   <EEE>eee</EEE>
> </AAA>
> 
> In words :
> There are nodes I want to delete (ie CCC) : I can do that
> There are nodes I want to copy (ie EEE) : I can do that also.
> 
> There is a node I want to copy (ie DDD) and modify conditionnally depending on
> another node's value (ie BBB):
> THIS IS WHAT I WAS NOT ABLE TO DO.
> 
Use:
<xsl:template match="/">
  <xsl:apply-templates  />
</xsl:template>
 
<!-- copy all-->
<xsl:template match="*">
  <xsl:copy>
     <xsl:copy-of select="@*"/>
     <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>
      
<!-- delete CCC-->
<xsl:template match="CCC | BBB" />

<!-- copy DDD and modify depending on BBB-->
<xsl:template match="DDD">
  <xsl:copy>
    <xsl:copy-of select="@*" />
    <xsl:if test="../BBB='bbb'" >
      <XXX><xsl:value-of select="../BBB"/></XXX>
    </xsl:if>
    <xsl:value-of select="." />
  </xsl:copy>
</xsl:template>


This does what you want, you need to nest the <xsl:if > inside the
<xsl:copy> to get the content inside the DDD tag in the output.

gavin

 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.