Kevin Burton wrote:
I don't think I understand the last() function.
It needs to be used in conjunction with something like position()
I have a document that looks like:
<Root>
<Header>Some text</Header>
<Message>
<MessageID>1</MessageID>
. . . .
</Message>
<Message>
. . . . .
</Message>
</Root>
I have an expression
node = doc.SelectSingl eNode("//Message/MessageID[last()]")
and
node = doc.SelectSingl eNode("//Message[last()]")
Neither of these seem to return the last node.
"Last node" is ambiguous here. If you want the last MessageID element in
each Message, then //Message/MessageID[position()=last ()] will return a
node-set containing those elements (in your example, two MessageID
elements, because you have two Message elements which match, each one
containing one MessageID element which occurs last).
For that reason, SelectSingleNod e cannot apply...so what "last" node do
you actually want? If it's the last MessageID in the entire document,
then //MessageID[position()=last ()] won't do it: that will still return
two elements.
//Message[position()=last ()]/MessageID[position()=last ()] would work...
Be careful of white-space: last() doesn't always do what you expect and
return the last element in a sequence. It ought to be called last-node()
and there should be a real last() function that returns the last element
of a sequence.
///Peter
--
XML FAQ:
http://xml.silmaril.ie/