getting first node in xpath result set

Use the following:

(//dl)[1]

The parentheses are significant. You want the first node that results from //dl (not the set of dl elements that are the first child of their parent (which is what //dl[1] (no parens) returns)).

This is easier to see when one realizes that // is shorthand for (i.e. expands fully to) /descendant-or-self::node()/ so that //dl[1] is equivalent to:

/descendant-or-self::node()/dl[1]

…which is more obviously not what you want. Instead, you’re looking for:

(/descendant-or-self::node()/dl)[1]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)