In the example below, I would expect the statement $div//xh:a[1] to
return the first <a> element, but instead, it  returns two <a> elements.
Curiously, if I filter for the second <a> element using [2], it works.
What am I missing?


xquery version "1.0-ml";
declare namespace xh = "http://www.w3.org/1999/xhtml";;

<lds-terms>
{
for $letter at $ctr in ("A")
let $url := concat( "http://scriptures.lds.org/en/bd/";, lower-case(
$letter ), "/contents" )    
let $page := xdmp:tidy( xdmp:http-get( $url )[2] )//xh:d...@class =
"contents"]
return
    for $div in $page//xh:d...@class = "topics"]
    return <term>{ $div//xh:a[1] }</term>
}
</lds-terms>


Stewart,

This is because your expression:

$div//xh:a[1]

Means return the first xh:a element child of any descendent node under
xh:d...@class = "topics"]. The fact that you get multiple nodes back
means that there are multiple descendent elements of a given
xh:d...@class = "topics"] that have an xh:a child.

What you probably want to do instead is:

($div//xh:a)[1]

Which means return the first node of the sequence $div//xh:a.

Kelly
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to