XQuery did not find the right child nodes.

Running the “similar” Xquery and Xquery (see bellow), searching for the same word, the results don’t match the same nodes, it return only the first artigo-texto (child node) of artigo element (parent).

I will use this Xquery to formulate a more complex one. (Ex. to get other elements)

Is it a wrong Xquery?
Is the problem in the Schema?

The attached file contain the Tamino Schema and XML DataLoader File.


The XQuery:

declare namespace tf=“http://namespaces.softwareag.com/tamino/TaminoFunction
declare namespace ino=“http://namespaces.softwareag.com/tamino/response2
for $a in input()/norma//artigo-texto
where tf:containsText($a, “fundamental”)
return { $a }

Results:

<?xml version="1.0" encoding="windows-1252" ?>
- <ino:response xmlns:ino=“http://namespaces.softwareag.com/tamino/response2” xmlns:xql=“XQL FAQ (XML Query Language - Frequently Asked Questions)”>
- <xq:query xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>
- <![CDATA[
declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"
declare namespace ino="http://namespaces.softwareag.com/tamino/response2"
for $a in input()/norma//artigo-texto
where tf:containsText($a, "fundamental")
return { $a }

]]>
</xq:query>
- <ino:message ino:returnvalue=“0”>
ino:messagelineXQuery Request processing</ino:messageline>
</ino:message>
- <xq:result xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>
-
Art 1
SAG_article.zip (79.2 KB)

Stuart (Software AG - UK) sent the following tip to me. I think it could be useful in other queries that use text retrieval; it runs fine, see the result bellow.

Thanks.

Stuart wrote:

The following query should do the trick:-

declare namespace tf=“http://namespaces.softwareag.com/tamino/TaminoFunction
declare namespace ino=“http://namespaces.softwareag.com/tamino/response2
for $a in input()/norma//artigo-texto
let $b := {$a}
where tf:containsText($b,“fundamental”)
return
{$b/*}

By creating separate elements to contain each arigto-texto element and then using containsText() function againest each of those elements solves the problem. I have no idea why this makes a difference and hopefully a developer will be able to explain. But I suspect it relates to the way containsText() works.


Result:

<?xml version="1.0" encoding="windows-1252" ?>
- <ino:response xmlns:ino=“http://namespaces.softwareag.com/tamino/response2” xmlns:xql=“XQL FAQ (XML Query Language - Frequently Asked Questions)”>
- <xq:query xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>
- <![CDATA[
declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"
declare namespace ino="http://namespaces.softwareag.com/tamino/response2"
for $a in input()/norma//artigo-texto
let $b := {$a}
where tf:containsText($b,"fundamental")
return
{$b/*}
]]>
</xq:query>
- <ino:message ino:returnvalue=“0”>
ino:messagelineXQuery Request processing</ino:messageline>
</ino:message>
- <xq:result xmlns:xq=“http://namespaces.softwareag.com/tamino/XQuery/result”>
-
Art. 5