所以我想distint-nodes
在for
子句中插入函数(参见下面的内容).我正在使用BaseX来达到这个目的.
这是我的代码:
<autores>{
for $a in doc("libros.xml")//libro
return
<autor>
<nombre>{
for $b in $a/autor
return concat($b/nombre,' ',$b/apellido)
}
</nombre>
{
for $c in doc("libros.xml")//libro
where $c/autor = $a/autor
return $c/titulo
}
</autor>
}
</autores>
Run Code Online (Sandbox Code Playgroud)
我想在第一个中使用这个函数,所以它只返回一个<autor/>
元素的唯一实例:
for $b in distinct-nodes($a/autor)
return concat($b/nombre,' ',$b/apellido)
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误(BaseX查询信息):
错误:停在G:/ Pruebas XML/XML/xqueryLibros.xq,6/31:[XPST0017]未知函数:fn:distinct-nodes.
为什么这个功能存在时是未知的?有什么我想念的吗?
编辑:我的目的是获取元素的唯一实例,$a/autor
其中$a/autor/nombre
和$a/autor/apellidos
文本值相同
<autores>
<autor>
<nombre>W. Stevens</nombre>
<titulo>TCP/IP Ilustrado</titulo>
<titulo>Programación Avanzada en el entorno Unix</titulo>
</autor>
<autor>
<nombre>W. Stevens</nombre>
<titulo>TCP/IP Ilustrado</titulo>
<titulo>Programación Avanzada en el entorno Unix</titulo>
</autor>
<autor>
<nombre>Serge Abiteboul Peter Buneman Dan Suciu</nombre>
<titulo>Datos en la Web</titulo>
</autor>
<autor>
<nombre/>
</autor>
</autores>
Run Code Online (Sandbox Code Playgroud)
没有标准的XQuery函数fn:distinct-nodes(...)
,XQuery只知道fn:distinct-values(...)
.
第三方XQuery函数库functx
知道一个functx:dinstinct-nodes(...)
函数,它再次作为标准XQuery函数实现.该库可以作为大多数XQuery实现的模块下载和导入,因为它只使用标准的XQuery函数.
如果<autor/>
包含的所有元素都是作者的名称,请考虑应用,fn:distinct-values(...)
然后重新创建<autor/>
元素.
出于性能原因,如果编译时间增加太多(库很大),则只提取所需的函数可能是合理的.另外请注意,某些功能具有更快的XQuery 3.0对应功能,利用了新的语言功能.
fn
是默认的XQuery函数名称空间,funct
由函数库定义.
归档时间: |
|
查看次数: |
1310 次 |
最近记录: |