|
Subject: Re: [xsl] Newbie : conditional node move From: Gavin Corfield <gavin@xxxxxxxxxxxxxxxxxx> Date: Wed, 16 May 2001 17:30:30 +0800 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Newbie : conditional node, Jarno Elovirta | Thread | [xsl] XSL/XPath expression, Eriksson Magnus |
| Re: [xsl] Problem of syntax of filt, Stephane . Le-Deaut | Date | [xsl] XSL/XPath expression, Eriksson Magnus |
| Month |