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

Re: Building select-clause dynamically with parameter

Subject: Re: Building select-clause dynamically with parameters
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 10 Dec 2002 13:07:07 -0800 (PST)
where clause as a parameter
Probably you think that the following applies the appropriate templates
to ***all*** of the set of the a "chapter" node and its descendents,
the string value of which contains the value of $query?

>     <xsl:template match="/">
>       <xsl:apply-templates 
> select="chapter[contains(descendant-or-self::*,$query)]"/>
>     </xsl:template>

This is wrong. The above code will apply a template only to every
"chapter" node, the text of which contains that of $query -- not to any
descendent of a "chapter", even if the descendent contains the text of
$query.

At first it may seem that a "chapter" will be selected if one of its
descendents contains $query -- this may not be the case. A "chapter"
may be selected even if none of its descendents (including its own
children text nodes) contains $query. This will be the case, when
$query is "made up" by the concatenation of the text of several
descendents.

It seems to me that the code above does not express at all what you
wanted.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




"Marko Petersen" <lg002237@xxxxxxxxxxxxxxxx> wrote in message
news:5.1.1.6.0.20021210194812.00bb66f0@xxxxxxxxxxxxxxxxxxx
> Hi,
> 
> I would like to pass some words into my XSL file which should be used
> to build an XPath query in xsl:apply-templates. For an example, the
following
> works, but only for one word:
> 
>     <?xml version="1.0" encoding="ISO-8859-1"?>
>     <xsl:stylesheet version="1.0"
>      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
> 
>     <xsl:param name="query"/>
> 
>     <xsl:template match="/">
>       <xsl:apply-templates 
> select="chapter[contains(descendant-or-self::*,$query)]"/>
>     </xsl:template>
> 
>     <xsl:template match="chapter | section">
>       <table>
>         <tr>
>           <td>&#160;</td>
>           <td>Found <xsl:value-of select="title"/>
>             <xsl:apply-templates 
> select="section[contains(descendant-or-self::*, $query)]"/>
>           </td>
>         </tr>
>       </table>
>     </xsl:template>
> 
>     </xsl:stylesheet>
> 
> I don't know how many words will be passed into the XSL file, this
should 
> be flexible.
> For example, If $query has the value "word1 word2", the only chapters
and 
> sections that
> should be selected by apply-templates are those which contain word1
or 
> word2, I think
> in this case need I something like:
> 
>       <xsl:apply-templates 
> select="chapter[contains(descendant-or-self::*,'word1') or
>                                                             
contains(descendant-or-self::*,'word2')]"/>
> 
> I tried to pass the whole string used by "select" as parameter, but
it does 
> not work.
> 
> Another thing is that I also have words that should be excluded and
that I 
> would like
> to pass a value into the XSL file that should define if it is an AND
or an 
> OR query to
> build something like:
> 
>       <xsl:apply-templates 
> select="chapter[contains(descendant-or-self::*,'word1') and
>                                                             
contains(descendant-or-self::*,'word2') 
> and
>                                                             
not(contains(descendant-or-self::*,'word3'))]"/>
> 
> Has anyone an idea how to do something like this? Or is it a better 
> solution to do this
> with Java DOM?
> 
> Thanks for help and greetings,
> 
> Marko
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

 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.