This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Filtering using XSL


Assuming <Main> wraps your entire XML file and true/false are
the only values for the Value attribute, the following
ought to work:

<xsl:template match="Main">
<xsl:apply templates select="Chapter"/>
</xsl:template>

<xsl:template match="Chapter[@Value='true']">
...do whatever you need to do to true chapters and their children..
</xsl:template>

<xsl:template match="Chapter[@Value='false']">
<xsl:choose>
<!-- the false chapter has children Chapters, so test them -->
 <xsl:when test="self::Chapter[Chapter]">
  <xsl:apply-templates select="./Chapter"/>
 </xsl:when>
 <xsl:otherwise>
<!-- nothing happens here because there are no children Chapters
     and the Value is false -->
 </xsl:otherwise>
</xsl:choose>
</xsl:template>

What happens is that the stylesheet matches the Main start tag. It
then selects each child chapter. Each of these chapters either matches
the template for Value=true or Value=false. If it's true, the template
does whatever you need it to do. If the chapter is false, it checks to
see if that Chapter has children Chapters. If that chapter has children
it processes the children and again they either match the true or false
template. If the current chapter is false and doesn't have any more children
the the template does nothing -- that Chapter is skipped. 

If Value can be something other than true/false, you need to change
the template that matches Chapter[@Value='false'] to match 
Chapter[not(@Value='true')] which will match any value of Value
that is NOT true.

Sara
> -----Original Message-----
> From: tmmet tvp [mailto:tmmet@hotmail.com]
> Sent: Thursday, February 10, 2000 11:17 AM
> To: xsl-list@mulberrytech.com
> Subject: RE: Filtering using XSL
> 
> 
> Thanks for your Mail...Ok...I'll start from scratch....
> My XML file is as follows...
> <Main>
>   <Chapter Value = "false">
>      <Chapter Value = "false">
>         <Chapter Value = "true"/>
>      </Chapter>
>   </Chapter>
> <Chapter Value = "false">
>     <Chapter Value = "true"/>
> </Chapter>
> <Chapter Value = "true"/>
> </Main>
> 
> I want to filter out all Chapters(including 
> children/descendants) with Value 
> = "false".
> So,I've to get only Main which contains Chapters(direct 
> children/descendants,children of Chapters) with Value = "true" after 
> transformation...
> In my xsl file,I tried the following possibilities...
> 
> 1.  <xsl:template match = "Main//Chapter[@Value = 'false']"/>
> 2. <xsl:template match = "Main[not(.//Chapter[@Value = 'false'])]"/>
> 
> Any ideas/suggestions will be graetly helpful for me...
> Thanks in advance...
> 
> 
> 
> 
> 
> 
> 
> 
> >From: Kay Michael <Michael.Kay@icl.com>
> >Reply-To: xsl-list@mulberrytech.com
> >To: "'xsl-list@mulberrytech.com'" <xsl-list@mulberrytech.com>
> >Subject: RE: Filtering using XSL
> >Date: Thu, 10 Feb 2000 18:50:21 -0000
> >
> > > It is filtering all the direct children Chapters of Main
> > > which has attribute value = 'true'.
> >
> >I think you need to make it clear whether you are using the word 
> >"filtering"
> >to mean "filtering through" or "filtering out".
> >
> >You probably need to go back to basics: show us a source 
> document and a
> >stylesheet, show us the output you want and the output you 
> are getting, and
> >tell us what processor you are using.
> >
> >Mike Kay
> >
> >
> >  XSL-List info and archive:  
> http://www.mulberrytech.com/xsl/xsl-list
> 
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]