I have following xml:
<test>
<TestStruktur>
<TestReference>ID_text_random_uuid</TestReference>
<TestReference>ID_test_random_uuid</TestReference>
<Name>Some name</Name>
</TestStruktur>
<TestStruktur>
<TestReference>ID_test_random_uuid</TestReference>
<TestReference>ID_text_random_uuid</TestReference>
<Name>Some name</Name>
</TestStruktur>
</test>
I need to search for TestReference elements and check if values contain test
string and then return value from the <Name>
element. I've created xquery that does it but it returns two values because the statement is true for two nodes.
Of course this is only a sample xml. I can have a lot of TestStruktur
nodes and even more TestReference
nodes
Here's my xquery:
declare function local:test($doc as node()) as xs:string {
for $test2 in $doc//test/TestStruktur
for $test in $test2/TestReference
return
if(contains($test, 'test')) then
data($test2/Name)
else ()
};
for $doc in collection('Testing')
return local:test($doc)
Is there any way to, for example, break loop when if statement is true?