2012-07-12 63 views
0

我想为参数化函数的XPATH过滤器,但希望有机会指示我想要所有结果。明显的例子xQuery变量持有通配符*(任意)

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. 

我怎么会效仿吗?是否有任何特殊的PARAM或语法传递*作为一个变量,所以我可以做

$var = * --> /Data/Books[@autor=$var] 

$var = EMPTY --> /Data/Books[@autor=$var] --> /Data/Books[@autor] 

谢谢!

回答

1

随着

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

你可以做

search-by-author('*') 
+0

酷!这确实是明显的。再次感谢你迈克尔! – Whimusical 2012-07-12 23:09:13