I've always been baffled by this interpretation - thanks for explaining.

Doesn't it seem as if .//foo *should* mean "descendant-or-self::foo" ? At least that is what every newcomer's interpretation seems to be. I guess one can't change the spec if that's not the case.

If it did, then .//foo[1] would do the thing that everybody seems to expect it to, and the parentheses wouldn't be necessary. In any case, this points out another idiom that can be used here, as an alternative to parentheses.

I can't help wondering is there some other case that would have been fouled up by this sort of elision?

I guess it would become more difficult to find all the eldest descendant foos, but that really does seem like an edge case.

-Mike

On 05/11/2011 04:16 PM, Evan Lenz wrote:
Just to explain why Geert's suggestion to add parentheses around $song-doc//ts:Value works, this doesn't really have anything to do with document vs. sequence order (they're one and the same), but with /which/ sequence(s) the predicate (the part in square brackets) is being applied to. The key is understanding what "//" is short for: "/descendant-or-self::node()/"

(.//foo)[1] means "get me all descendant <foo> elements and then return just the first one" (returning a maximum of one node). In this case, the predicate "[1]" applies to the whole (parenthesized) expression to its left.

.//foo[1] means "get me /every/ descendant <foo> element that is the first <foo> child of its parent". This expression could return /many/ <foo> elements (which is what you were experiencing with all those <ts:Value> elements). In this case, the predicate "[1]" is tightly bound to "foo" and applies only to the third step of the expression (where the steps are, respectively, ".", "descendant-or-self::node()", and "foo[1]").

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

Reply via email to