[plexippus-xpath-devel] do-node-set woes

Peter Stiernström peter at stiernstrom.se
Tue May 26 11:01:00 UTC 2009


Hello xpath developers,

I am trying to use plexippus-xpath and have hit a wall concerning the
use of evaluate together with do-node-set. I am under the impression
that the the second argument given to evaluate should be a document or
a node. What I am trying to accomplish is to write a function that
runs various xpath expressions on a subset of the document like so:

(let ((doc (cxml:parse "<a><b><c><d>1</d></c><c><d>2</d></c><c><d>3</d></c></b></a>" 
                       (cxml-dom:make-dom-builder))))
  (xpath:do-node-set (n (xpath:evaluate "//c" doc))
    (format t "~d~%" (xpath:number-value (xpath:evaluate "//d" n)))))

I would like to have this print:
1
2
3

But instead it always prints:
1
1
1

If I instead change my code to this:

(let ((doc (cxml:parse "<a><b><c><d>1</d></c><c><d>2</d></c><c><d>3</d></c></b></a>" 
                       (cxml-dom:make-dom-builder))))
  (xpath:do-node-set (n (xpath:evaluate "//c" doc))
    (format t "~a~%" (dom:map-document (cxml:make-string-sink) n))))

It prints (as expected):

<?xml version="1.0" encoding="UTF-8"?>
<d>1</d>
<?xml version="1.0" encoding="UTF-8"?>
<d>2</d>
<?xml version="1.0" encoding="UTF-8"?>
<d>3</d>

So my conclusion is that somehow my use of evaluate does not work
according to my expectations, if those are valid or not is something I
leave up to you to decide :)

Now please strike me with your clue sticks!

/ Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <https://mailman.common-lisp.net/pipermail/plexippus-xpath-devel/attachments/20090526/8e6b4424/attachment.sig>


More information about the plexippus-xpath-devel mailing list