如何通过xquery中的变量选择属性? [英] How to select an attribute by a variable in xquery?
本文介绍了如何通过xquery中的变量选择属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何选择这样的属性:
I know how to select an attribute like so:
$table/@id
但是,如果属性名称存储为变量,我该怎么做.例如:
However how do I do this if the attribute name is stored as a variable. For example:
let $x = "id"
$table/@[$x]
推荐答案
您可以使用函数local-name
或 node-name
来捕获属性的值并将其与谓词匹配.local-name
将简单地返回一个与元素名称匹配的字符串,而 node-name
将返回一个完全限定的名称,这通常是推荐的,但实际上只是如果您正在处理命名空间,则很有必要.
You can use the functions local-name
or node-name
to capture the value of the attribute and match it the predicate. local-name
will simply return a string that matches the element name, and node-name
will return a fully qualified name, which is generally recommended, but practically speaking, is only necessary if you are dealing with namespaces.
let $x = "id"
return $table/@*[local-name(.) = $x]
let $x := xs:QName("id")
return $table/@*[node-name(.) = $x]
这篇关于如何通过xquery中的变量选择属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文