RE: Newbie question - dynamic filter on attribute values

Subject: RE: Newbie question - dynamic filter on attribute values
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Wed, 16 Feb 2000 18:45:52 -0000
If you can get the list of attribute numbers you are interested in into a
node-set $wanted, then you're home and dry: you can write logic like <if
test="@attr=$wanted"> or <for-each select="chap[@attr=$wanted]"> which tests
whether the @attr attribute is equal to any one of the nodes in $wanted.

So how to establish the node-set? The only standard way to do it is to
create a secondary XML document containing the required numbers, and read it
using the document() function. There was a similar solution posted earlier
today. Or you could use various non-standard facilities, for example you
could pass in a space-separated list of numbers and turn it into a node-set
using Saxon's new tokenize() extension function.

Mike Kay

> -----Original Message-----
> From: Super, Karen [mailto:Karen.Super@xxxxxxxxxxxxx]
> Sent: 16 February 2000 17:59
> To: 'XSL-List@xxxxxxxxxxxxxxxx'
> Subject: Newbie question - dynamic filter on attribute values
> 
> 
> I apologize if this has already been discussed, but I am new 
> to XML and XSLT
> and have been reading some of the posts and haven't seem to 
> come across my
> situation.  I have data similar to the following:
> 
> <book attr="1">
>     <title attr="10">This is the title</title>
>     <chap attr="20">
>         <title attr="25">Chapter title 1</title>
>         <para attr="26">This is a paragraph in the first 
> chapter</para>
>     </chap>        
>     <chap attr="20">
>         <title attr="25">Chapter title 2</title>
>         <para attr="26">This is a paragraph in the second 
> chapter</para>
>     </chap>        
> </book>
> 
> I would like to initially filter out my document based on the 
> attr values.
> I will be receiving an array of numbers that correspond to 
> the numbers in
> attr.  I only want those elements that match these numbers.  
> For example, if
> I receive 25 and 26, I only want to work with the <title> and <para>
> elements.  This array of numbers that I will be receiving 
> will vary from
> request to request, meaning I may get a request for only 10 
> and 25, or just
> 26.  I would like to somehow dynamically combine this logic into the
> following stylesheet, but I am not sure how to do it.
> 
> <xsl:template match="chap/title">
>     <FormatScope>
> 	 <Format>
> 	     <ESC/>TB
> 		 </Format>
> 		 <Content>
> 		     <xsl:apply-templates/>
> 		 </Content>
> 		 <Format>
> 		     <ESC/>TE
> 		 </Format>
>     </FormatScope>
> </xsl:template>
> 
> <xsl:template match="para">
>     <FormatScope>
>         <Format>
>             <ESC/>PB
>         </Format>
>         <Content>
>             <xsl:apply-templates/>
>         </Content>
>         <Format>
>             <ESC/>PE
>         </Format>
>     </FormatScope>
> </xsl:template>
>   
> The resulting XML would be:
> 
> <FormatScope>
>     <Format>
>         <ESC/>TB
>     </Format>
>     <Content>Chapter title 1</Content>
>     <Format>
>         <ESC/>TE
>     </Format>
> </FormatScope>
> 
> <FormatScope>
>     <Format>
>         <ESC/>PB
>     </Format>
>     <Content>This is a paragraph in the first chapter</Content>
>     <Format>
>         <ESC/>PE
>     </Format>
> </FormatScope>
> 
> <FormatScope>
>     <Format>
>         <ESC/>TB
>     </Format>
>     <Content>Chapter title 2</Content>
>     <Format>
>         <ESC/>TE
>     </Format>
> </FormatScope>
> 
> <FormatScope>
>     <Format>
>         <ESC/>PB
>     </Format>
>     <Content>This is a paragraph in the second chapter</Content>
>     <Format>
>         <ESC/>PE
>     </Format>
> </FormatScope>
> 
> 
> Using XSLT, is there a way to do what I am trying to accomplish?  Any
> suggestions are greatly appreciated.
> 
> Thanks,
> Karen
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


Current Thread