Skip to content Skip to sidebar Skip to footer

X Path Not Counting Second Element

i have a xpath set to search for the first and second heading however the second comes up as blank, im guessing this must be pretty easy however ive tried changing the path names s

Solution 1:

How about this:

<li><ahref="#"class ="Part 1"><xsl:value-ofselect="//foo:Entry[1]/foo:Heading"/></a></li><li><ahref="#"class ="Part 2"><xsl:value-ofselect="//foo:Entry[2]/foo:Heading"/></a></li>

Alternatively, this should work too:

<li><ahref="#"class ="Part 1"><xsl:value-ofselect="(//foo:Heading)[1]"/></a></li><li><ahref="#"class ="Part 2"><xsl:value-ofselect="(//foo:Heading)[2]"/></a></li>

From the almighty XPath spec:

// is short for /descendant-or-self::node()/. For example, //para is short for /descendant-or-self::node()/child::para and so will select any para element in the document (even a para element that is a document element will be selected by //para since the document element node is a child of the root node); div//para is short for div/descendant-or-self::node()/child::para and so will select all para descendants of div children.

NOTE: The location path //para[1] does not mean the same as the location path /descendant::para[1]. The latter selects the first descendant para element; the former selects all descendant para elements that are the first para children of their parents.

Post a Comment for "X Path Not Counting Second Element"