For example:
let $targetAtt "= "att1";
let $doc := <Xml att1 = "la", att2开发者_运维问答 = "la la">
So this works:
return $doc/@*[(name(.) = $targetAtt)]
But is a more succinct syntax possible?
For example: the following Does not work
such as
return $doc/@$targetAtt.
Thanks !
Short answer: no.
A path expression requires a literal NameTest. There is no way around this. Some implementations may provide an eval function, eg eval(concat("$doc/@", $targetAtt))
but in general this is to be avoided if it can be at all helped.
The only way to tidy the syntax in vanilla XQuery is with a user defined function:
declare function local:attribute($node as node(), $name as xs:QName)
{
$node/@*[name(.) = $name]
};
local:attribute($doc, $targetAtt)
精彩评论