1

我想为函数参数化 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]

谢谢!

4

1 回答 1

1

declare function search-by-author($author as xs:string*) as element()*{
   /Data/Books[$author='*' or @autor=$author]
};

你可以做

search-by-author('*')
于 2012-07-12T23:07:09.413 回答