Result of // Use is Unexpected
I have a node that is present in two places in my input XML, called "elementA".
The first instance has the value "aaa" and the second instance has the value "bbb".
If I set a variable called "thisVar" to "//elementA[1]" I would expect it to fetch the first elementA node that it finds (since //elementA returns two nodes, and the [1] predicate states I want node 1).
If I then use value-of select="$thisVar", it outputs the two elementA values concatenated, i.e. "aaa bbb".
There are also two nodes in $thisVar, both have the above value.
However, if I set the variable to simply be "//elementA" and then when calling the variable in the value-of, I use the predicate there instead, it works as expected.
I.e. using value-of select="$thisVar[1]" gets me a single node with the value "aaa".
I'm intrigued as to why the first solution doesn't produce the same result as the second solution.
Any info appreciated, thanks.
__________________
Neil Belch
Technical Officer
CDL
The views opinions and judgements expressed in this message are solely those of the author. The message contents have not been reviewed or approved by CDL.
|