Re: [xsl] Re: Re: Re: Sibling in the Pattern(match)

Subject: Re: [xsl] Re: Re: Re: Sibling in the Pattern(match)
From: Dongling Ding <dling61@xxxxxxxxx>
Date: Tue, 25 Nov 2003 09:57:39 -0800 (PST)
Thanks a lot Dimitre,

But because the member with "acc11" can exist in more
than one places in the source file. That is the reason
I wanted to use the full path to indicate that 
particular member.

However, "Member[@name
='acc1']/Member[@name='acc11']]" seems not okay in the
match. It only recognized the "Member[@name='acc1'],
not the full path.

Here is the example code I modified. So, here there
are two members with "acc11". One is the child of
member with "acc1"; another is the child of member
with "acc3". I only want to process nothing with the
first one, but keep others same. 

Maybe this is the restriction on the "predicates".


Thanks

Dongling

<D>
   <Member comment="" name="acc1">
     <Calc>+</Calc>
     <Member comment="" name="acc11">
       <Calc>+</Calc>
       <Member name="account3_1"/>
     </Member>
     <Member comment="" name="acc12">
       <Calc>+</Calc>
       <Member name="acc121"/>
     </Member>
   </Member>
   <Member comment="" name="acc2">
     <Calc>+</Calc>
   </Member>
   <Member comment="" name="acc3">
     <Calc>+</Calc>
     <Member comment="" name="acc31">
       <Calc>+</Calc>
     </Member>
     <Member comment="" name="acc11">
       <Calc>+</Calc>
     </Member>
   </Member>
<\D>



--- Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> > The following template can act like a filter since
> it
> > does nothing. The attribute "match" here indicate
> what
> > needs to be filtered out from the output.
> >
> > <xsl:template
> match="*[preceding-sibling::Member[@name
> > ='acc1']/Member[@name='acc11']]"/>
> >
> >
> > Here I wanted to remove(filter out) the element
> > Member(name attribute is "acc12") and its children
> > from the output. It is the sibling of the element
> > Member(name attribute is "acc11").
> 
> 
> Use:
> 
>   <xsl:template
>    match="*[preceding-sibling::Member
>                           [@name='acc11']
>             ]"/>
> 
> This removes any element that is a following-sibling
> of a "Member" element
> whose "name" attribute's value is "acc11".
> 
> In the case of the source xml provided by you, the
> element removed will be a
> "Member" element with "acc12" as the value of its
> "name" attribute.
> 
> All the children of this removed element will also
> be removed, because they
> are not processed at all.
> 
> So, given this source.xml:
> 
> <D>
>   <Member comment="" name="acc1">
>     <Calc>+</Calc>
>     <Member comment="" name="acc11">
>       <Calc>+</Calc>
>       <Member name="account3_1"/>
>     </Member>
>     <Member comment="" name="acc12">
>       <Calc>+</Calc>
>       <Member name="acc121"/>
>     </Member>
>   </Member>
>   <Member comment="" name="acc2">
>     <Calc>+</Calc>
>   </Member>
>   <Member comment="" name="acc3">
>     <Calc>+</Calc>
>     <Member comment="" name="acc31">
>       <Calc>+</Calc>
>     </Member>
>     <Member comment="" name="acc32">
>       <Calc>+</Calc>
>     </Member>
>   </Member>
> </D>
> 
> When we apply this transformation on it:
> 
> <xsl:stylesheet version="1.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> 
>  <xsl:output omit-xml-declaration="yes"/>
> 
>   <xsl:template match="@* | node()">
>     <xsl:copy>
>       <xsl:apply-templates select="@* | node()"/>
>     </xsl:copy>
>   </xsl:template>
> 
>   <xsl:template
>    match="*[preceding-sibling::Member
>                           [@name='acc11']
>             ]"/>
> 
> </xsl:stylesheet>
> 
> the wanted result is produced:
> 
> <D>
>   <Member comment="" name="acc1">
>     <Calc>+</Calc>
>     <Member comment="" name="acc11">
>       <Calc>+</Calc>
>       <Member name="account3_1"></Member>
>     </Member>
> 
>   </Member>
>   <Member comment="" name="acc2">
>     <Calc>+</Calc>
>   </Member>
>   <Member comment="" name="acc3">
>     <Calc>+</Calc>
>     <Member comment="" name="acc31">
>       <Calc>+</Calc>
>     </Member>
>     <Member comment="" name="acc32">
>       <Calc>+</Calc>
>     </Member>
>   </Member>
> </D>
> 
> 
> =====
> Cheers,
> 
> Dimitre Novatchev.
> http://fxsl.sourceforge.net/ -- the home of FXSL
> 
> 
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> ve:  http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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


Current Thread