How to get element type in xpath?
xpath, xquery
Solution
Another neat XQuery solution is to use typeswitch:
for $i in $records/record/field | $records/record/id
return
typeswitch($i)
case element(id) return ...
case element(field) return ...
default return ...
Problem
My xml is: ``` <record> <field name="f1"/> <id name="f2"/> <id name="f3"/> <field name="f4"/> <info/> </record> ``` I want to loop through it in xquery like this: ``` for $i in $records/record/field | $records/record/id return if ( .... $i is id .... ) then .... do something .... else ... do something else ... ``` Is this possible? How can distinguish when `$i` is id and when it is field?