如果我不使用函数,我的代码工作正常。
declare function local:samlefamily(
$pers as xs:string?) as xs:string?
{
some stuff
};
if (exists(/*/FamilyRec/Child/Link[@Ref = "IN0099"]))
then
for $family in doc("family.xml") /*/FamilyRec
where $family/Child/Link[@Ref = "IN0099"]
return if (local:samlefamily(data($family/HusbFath/Link/@Ref))) then local:samlefamily(data($family/HusbFath/Link/@Ref)) else "na1"
else "na2"
但是当我尝试定义函数
时会出现问题declare function local:giveParent($pers as xs:string) as xs:string
{if (exists(/*/FamilyRec/Child/Link[@Ref = $pers]))
then
for $family in doc("gedcom.xml") /*/FamilyRec
where $family/Child/Link[@Ref = $pers]
return if (local:samlefamily(data($family/HusbFath/Link/@Ref))) then local:samlefamily(data($family/HusbFath/Link/@Ref)) else "na1"
else "na2"
};
我收到错误: 描述:意外的标记“< eof>”在路径表达式
传递参数($ pers)不会发生。即使我使用静态(“IN0099”)参数,我得到同样的错误。 有人可以帮忙吗?我不能在用户定义的函数中使用If ... else吗?高级感谢您的支持
答案 0 :(得分:1)
你需要在xquery文件中至少有一个非函数语句,即在最后一个分号后添加任何内容
否则您的代码看起来很好