I search through an XML file with this query:
declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"
declare namespace ino = "http://namespaces.softwareag.com/tamino/response2"
for $q in input()/test
where $q//*[tf:containsText(., "test")]
return <result>{$q/Title}<ino:id>{tf:getInoId($q)}</ino:id><searchresult>{$q//*[tf:containsText(., "test")]}</searchresult></result>
As result I expect only the elements, which the searched string “test” contain.
But as results I get all nodes and elements from the root to the next upper node of the element.
What’s wrong with the query?
Example XML-file:
<?xml version="1.0" encoding="UTF-8"?>
<UseCaseSpec xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
<Title DocID="1234">test</Title>
<DocInfo CommentsFlag="true" Continued="true" References="true">
<Template>
<TempName>String</TempName>
<TempVersion>0.0</TempVersion>
</Template>
<Authors>
<Author>
<AuthorName>String</AuthorName>
<AuthorDept>String</AuthorDept>
</Author>
</Authors>
<Abbreviations>
<Abbreviation>
<A_Term>String</A_Term>
<A_Definition>String</A_Definition>
</Abbreviation>
</Abbreviations>
<References>
<RefReferences>
<RefID>String</RefID>
<RefTitle>String</RefTitle>
</RefReferences>
</References>
<Product>test hallo</Product>
</DocInfo>
</UseCaseSpec>
If I search the string “test” I get “test hallo” as one result an the howle node “DocInfo” with all lower nodes another result.