[xquery-talk] Wild Card in 'Where' Clause
Michael Kay
mhk at mhk.me.uk
Fri Aug 26 00:09:34 PDT 2005
Use
where $brunch = ($alum/@brunch, "either") and
$intl = ($alum/@intl, "either")
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: talk-bounces at xquery.com
> [mailto:talk-bounces at xquery.com] On Behalf Of McAuley, Grant (LLU)
> Sent: 25 August 2005 20:54
> To: talk at xquery.com
> Subject: [xquery-talk] Wild Card in 'Where' Clause
>
>
> ///Xml fragment:///////////////////////
>
> <alumnus brunch="yes" intl="no">
> <name>Sally Smith</name>
> </alumnus>
>
>
> ///XQuery function:////////////////////
>
> declare function local:getTableRows($brunch as xs:string, $intl as
> xs:string) as element()* {
>
> let $col := collection(" ... ")
> for $alum in $col/alumnus
> where ($alum[@brunch = $brunch] and $alum[@intl = $intl])
> return
> <tr>
> <td>{ $alum/name/text() }</td>
> </tr>
>
> };
>
>
> For the xml fragment above the 'brunch' and 'intl' attributes can take
> values of 'yes' or 'no'. However, I would like to be able to pass
> 'either' to $intl and $brunch in the xquery function, so that
> my results
> can show e.g., fragments where the 'intl' attribute is either 'yes' or
> 'no' and 'brunch' is 'yes' (using this call: getTableRows("either",
> "yes")). The problem is that 'either' is not in the xml.
>
> One way to do this is to use a 'where' clause like:
>
> where ($alum[@brunch = $brunch] and $alum[@intl = $intl]) or
> ($alum[@brunch = $brunch] and $intl = 'either') or
> ($brunch = 'either' and $alum[@intl = $intl]) or
> ($brunch = 'either' and $intl = 'either')
>
> This seems to work but if I have to add another 'either'/'something'
> condition this will get even more ugly.
>
> So my question (finally):
>
> 1) Is there some kind of 'wildcard' construct I could use in the where
> clause? Something resulting in:
> where $alum[@brunch = 'yes'] and $alum[@intl = '*'] (via
> getTableRow('yes', '*')), so that no tuples fill be filtered based on
> the 'intl' attribute? In other words, here '*' has the meaning such
> that '$alum[@intl = '*']' pass all fragments whatever the value of the
> 'intl' attribute.
>
> 2) If not, is there a better way to do this?
>
> Any help would be appreciated.
>
>
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
>
More information about the talk
mailing list