For analyzing some data, I am currently trying to select an attribute in XQuery. Unfortunately, for some reason I can't select it.
Considering the example document
<myroot>
<betweennode>
<asd name="test">
<asdasd/>
</asd>
</betweennode>
</myroot>
the XPath /myroot/betweennode/asd/@name
regulary returns test
, the XQuery
for $x in /myroot/betweennode/asd
return $x
returns
<asd name="test">
<asdasd/>
</asd>
but the XQuery
for $x in /myroot/betweennode/asd
return $x/@name
does not work (it returns 'ERROR - Cannot create an attribute node (name) whose parent is a document node' in http://www.xpathtester.com/xquery and '[SENR0001] Attributes cannot be serialized:attribute name {"testInitialize"}.' when I use BaseX and doc('mydoc.xml')/myroot/betweennode/asd in the for-statement).
Could anyone give me a hint why this doesn't work, and how selecting all attributes works in XQuery?