我想为函数参数化XPATH过滤器,但是希望有机会指出我想要所有结果。清楚的例子
declare function search-by-author($author as xs:string*) as element()*{
/Data/Books[@autor=$author]
};
search-by-author(()) -> If null no results even if some books did not have @autor attr
search-by-author('') -> If empty, only shows those books with @author=''
search-by-author(('a','b')) -> Returns books by authors 'a' or 'b'
search-by-author(*) -> THIS MY CURRENT PROBLEM.
我怎么能模仿这个?有没有特殊的参数或语法来传递*作为变量,所以我可以做
$var = * --> /Data/Books[@autor=$var]
或
$var = EMPTY --> /Data/Books[@autor=$var] --> /Data/Books[@autor]
谢谢!
答案 0 :(得分:1)
使用
declare function search-by-author($author as xs:string*) as element()*{
/Data/Books[$author='*' or @autor=$author]
};
你可以做到
search-by-author('*')