From peter at stiernstrom.se Tue May 26 11:01:00 2009 From: peter at stiernstrom.se (Peter =?iso-8859-1?Q?Stiernstr=F6m?=) Date: Tue, 26 May 2009 13:01:00 +0200 Subject: [plexippus-xpath-devel] do-node-set woes Message-ID: <20090526110100.GA27718@peter.stiernstrom.se> 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 "123" (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 "123" (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): 1 2 3 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: From david at lichteblau.com Tue May 26 11:05:08 2009 From: david at lichteblau.com (David Lichteblau) Date: Tue, 26 May 2009 13:05:08 +0200 Subject: [plexippus-xpath-devel] do-node-set woes In-Reply-To: <20090526110100.GA27718@peter.stiernstrom.se> References: <20090526110100.GA27718@peter.stiernstrom.se> Message-ID: <20090526110508.GB4563@radon> Quoting Peter Stiernstr?m (peter at stiernstrom.se): > (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 Use ".//d" rather than "//d". The latter doesn't start at N, it starts at the root of the document, ignoring the context node N. d. From ivan4th at gmail.com Tue May 26 11:12:28 2009 From: ivan4th at gmail.com (Ivan Shvedunov) Date: Tue, 26 May 2009 15:12:28 +0400 Subject: [plexippus-xpath-devel] do-node-set woes In-Reply-To: <20090526110100.GA27718@peter.stiernstrom.se> References: <20090526110100.GA27718@peter.stiernstrom.se> Message-ID: <4d93c5bf0905260412w49a5d86cracef6dcc67b775bc@mail.gmail.com> Hello, 2009/5/26 Peter Stiernstr?m : > 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 "123" > ? ? ? ? ? ? ? ? ? ? ? (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 It should be noted that //c in the last expression (same as /descendant-or-self::node()/c) works relative to the root node of the document and not the context node, thus you get 1 every time. Perhaps what you want is descendant::d as the last expression (.//d will also work in this concrete case though). (let ((doc (cxml:parse "123" (cxml-dom:make-dom-builder)))) (xpath:do-node-set (n (xpath:evaluate "//c" doc)) (format t "~d~%" (xpath:number-value (xpath:evaluate "descendant::d" n))))) (I'd write the FORMAT form as (format t "~d~%" (xpath:evaluate "number(descendant::d)" n)) though). > If I instead change my code to this: > > (let ((doc (cxml:parse "123" > ? ? ? ? ? ? ? ? ? ? ? (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): > > > 1 > > 2 > > 3 > > 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! > Well, in this case the second expression is absent, so there's no problem :) Ivan. From peter at stiernstrom.se Tue May 26 11:42:00 2009 From: peter at stiernstrom.se (Peter =?iso-8859-1?Q?Stiernstr=F6m?=) Date: Tue, 26 May 2009 13:42:00 +0200 Subject: [plexippus-xpath-devel] do-node-set woes In-Reply-To: <4d93c5bf0905260412w49a5d86cracef6dcc67b775bc@mail.gmail.com> References: <20090526110100.GA27718@peter.stiernstrom.se> <4d93c5bf0905260412w49a5d86cracef6dcc67b775bc@mail.gmail.com> Message-ID: <20090526114200.GA29283@peter.stiernstrom.se> Thank you Ivan and David, You are of course both correct that the error was in my xpath-fu and not plexippus. I am thouroughly ashamed of this newbie question and will make sure to inspect my expressions more vigirously before posting again! /Peter On Tue, May 26, 2009 at 03:12:28PM +0400, Ivan Shvedunov wrote: > Hello, > > 2009/5/26 Peter Stiernstr?m : > > 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 "123" > > ? ? ? ? ? ? ? ? ? ? ? (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 > > It should be noted that //c in the last expression (same as > /descendant-or-self::node()/c) works > relative to the root node of the document and not the context node, > thus you get 1 every time. > Perhaps what you want is descendant::d as the last expression (.//d > will also work in this > concrete case though). > > (let ((doc (cxml:parse > "123" > (cxml-dom:make-dom-builder)))) > (xpath:do-node-set (n (xpath:evaluate "//c" doc)) > (format t "~d~%" (xpath:number-value > (xpath:evaluate "descendant::d" n))))) > > (I'd write the FORMAT form as (format t "~d~%" (xpath:evaluate > "number(descendant::d)" n)) though). > > > If I instead change my code to this: > > > > (let ((doc (cxml:parse "123" > > ? ? ? ? ? ? ? ? ? ? ? (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): > > > > > > 1 > > > > 2 > > > > 3 > > > > 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! > > > > Well, in this case the second expression is absent, so there's no problem :) > > Ivan. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: Digital signature URL: