You need to add a condition with position()
Xpath function to the end of a XQuery expression:
...
XMLTable(
'/OrderVal[1]/Orderattrs/Orderattr[1]/OrderVals/OrderVal[1]/Orderattrs/Orderattr[position() <= 25]'
...
SQLFiddle test with your exapmle
Update
Question updated, so a little bit more about XMLQuery()
function.
First of all, this function return single XMLType, therefore to get individual elements you need to use ExtractValue()
function:
with params as (
select XMLParse(content '
<draftorders>
<!-- EXAMPLE XML FROM QUESTION GOES HERE -->
</draftorders>
')
doc from dual
)
select
ExtractValue(xml_val, '/Orderattr/@Ordername') order_name,
ExtractValue(xml_val, '/Orderattr/OrderVals/OrderVal[1]/listvalue') list_value
from (
SELECT
XMLQuery(
'//OrderVal[1]/Orderattrs/Orderattr[1]/OrderVals/OrderVal[1]/Orderattrs/Orderattr[position() < 2]'
PASSING doc returning content
) xml_val
from
params
);
SQLFiddle test for XMLQuery variant
Second: if your XQuery return set of nodes then resulting XML not well-formed because there are no single root node.
Last: In your variant with XMLQuery expression returns set of values, not XML. All value sequences in XQuery concatenated without separators, so you got what you got:
Node2_Child1<![CDATA[ Node2_Child1_OrderValue_1]]>Node2_Child2<![CDATA[ Node2_Child2_OrderValue_1]]>
and after evaluation this expression translated to just
Node2_Child1Node2_Child1_OrderValue_1Node2_Child2Node2_Child2_OrderValue_1
Oops... You mistyped @Ordername
and changed it to @listname
at least in question text, so this part returns empty string and if this expression evaluated without changes result would be like
Node2_Child1_OrderValue_1Node2_Child2_OrderValue_1