[xquery-talk] Wild Card in 'Where' Clause
McAuley, Grant (LLU)
gmcauley at llu.edu
Thu Aug 25 13:53:44 PDT 2005
///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.
More information about the talk
mailing list