Below is an example of a test example of my xml file:
test.xml
<feed> <entry> <title>Link ISBN</title> <libx:libapp xmlns:libx="http://libx.org/xml/libx2" /> </entry> <entry> <title>Link Something</title> <libx:module xmlns:libx="http://libx.org/xml/libx2" /> </entry> </feed>
Now I want to write an xquery that will find all the <entry> elements for which <libx:libapp> will be a child. Then, for all such records, the title is returned if the title contains the specified keyword (for example, a link). So, in my example xml document, xquery should return βLink ISBNβ.
My xquery example is shown below:
samplequery.xq (here doc_name is the xml file shown above, and libapp_matchkey is a keyword such as "Link")
declare namespace libx='http://libx.org/xml/libx2'; declare variable $doc_name as xs:string external; declare variable $libpp_matchkey as xs:string external; let $feeds_doc := doc($doc_name) for $entry in $feeds_doc/feed/entry (: test whether entry has libx:libapp child and has "Link" in its title child :) where ($entry/libx:libapp and $entry/title/text()[contains(.,$libapp_matchkey)]) return $entry/title/text()
This xquery returns null instead of the expected result of 'Link ISBN'. Why is this?
source share