Discussion:
[xquery-talk] Return nodes and text between nodes
Gary Larsen
2017-11-09 18:27:33 UTC
Permalink
Hi,



Trying to process both node and text children in a for loop. For some
reason this escapes me.



let $expr :=
<expression><refobj>REFOBJ1</refobj>TEXT1<refobj>REFOBJ2</refobj></expressio
n>

for $x in $expr/* return $x



This returns:



<refobj>REFOBJ1</refobj>
<refobj>REFOBJ2</refobj>



How do I access TEXT1 in a loop?



Thanks,

Gary
Ronald Bourret
2017-11-09 18:40:23 UTC
Permalink
From the XPath specification:

- child::* selects all element children of the context node

- child::text() selects all text node children of the context node

- child::node() selects all the children of the context node, whatever
their node type

Since "child" is the default axis, you can omit it. Thus, $expr/* will
only return element children, as you have seen. If you want all
children, use $expr/node(). If you only want text children, use
$expr/text().

-- Ron
Hi,
Trying to process both node and text children in a for loop.  For some
reason this escapes me.
let $expr :=
<expression><refobj>REFOBJ1</refobj>TEXT1<refobj>REFOBJ2</refobj></expression>
for $x in $expr/* return $x
<refobj>REFOBJ1</refobj>
<refobj>REFOBJ2</refobj>
How do I access TEXT1 in a loop?
Thanks,
Gary
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk

Loading...