From rm at mh-freiburg.de Tue May 8 19:42:21 2012 From: rm at mh-freiburg.de (R. Mattes) Date: Tue, 8 May 2012 21:42:21 +0200 Subject: [xuriella-devel] Question concerning custom xpath functions returning node sets Message-ID: <20120508192505.M67880@mh-freiburg.de> Dear list, I'm trying to extend xuriella by writing some custom xpath functions (using plexippus' extension mechanism). This works fine for functions returning strings, booleans or numbers, but I now need to write a function that returns a node set so that the following will work: My first (naive) implementation looked like this: (xpath-sys:define-xpath-function/eager my fun (string &optional (count 1)) (loop for i from 0 to count collect string into value-list finally (return (xpath-sys:make-node-set (xpath-sys:make-pipe (car value-list) (cdr value-list)))))) Testing seem to work: CL-USER> (xpath:with-namespaces (("my" "http://my.ns")) (xpath:evaluate "my:myfun('blah')" nil)) # A nodeset, as expected. But using this function in a stylesheet throw the following error: CL-USER> (xuriella:apply-stylesheet #p"test.xsl" #p"test.xsl") There is no applicable method for the generic function # when called with arguments (:DEFAULT-NAVIGATOR "sample string"). [Condition of type SIMPLE-ERROR] What do I miss? (besides better documentation ;-) TIA Ralf Mattes From david at lichteblau.com Sun May 20 14:39:29 2012 From: david at lichteblau.com (David Lichteblau) Date: Sun, 20 May 2012 16:39:29 +0200 Subject: [xuriella-devel] Question concerning custom xpath functions returning node sets In-Reply-To: <20120508192505.M67880@mh-freiburg.de> References: <20120508192505.M67880@mh-freiburg.de> Message-ID: <20120520143929.GB12273@radon> Hi, Quoting R. Mattes (rm at mh-freiburg.de): > My first (naive) implementation looked like this: > > (xpath-sys:define-xpath-function/eager > my fun (string &optional (count 1)) > (loop for i from 0 to count > collect string into value-list > finally (return (xpath-sys:make-node-set > (xpath-sys:make-pipe (car value-list) (cdr > value-list)))))) sorry for the late reply. I suspect that by now you might have come up with a solution yourself, so I'll keep my answer brief for now: I think you need to return a set of nodes, whereas you have a set of strings, and a string as such isn't a node. If the above is too obscure, please let me know, and I'll elaborate! :-) d. From rm at tuxteam.de Sun May 20 17:45:19 2012 From: rm at tuxteam.de (rm at tuxteam.de) Date: Sun, 20 May 2012 19:45:19 +0200 Subject: [xuriella-devel] Question concerning custom xpath functions returning node sets In-Reply-To: <20120520143929.GB12273@radon> References: <20120508192505.M67880@mh-freiburg.de> <20120520143929.GB12273@radon> Message-ID: <20120520174518.GB19722@seid-online.de> On Sun, May 20, 2012 at 04:39:29PM +0200, David Lichteblau wrote: > Hi, > > Quoting R. Mattes (rm at mh-freiburg.de): > > My first (naive) implementation looked like this: > > > > (xpath-sys:define-xpath-function/eager > > my fun (string &optional (count 1)) > > (loop for i from 0 to count > > collect string into value-list > > finally (return (xpath-sys:make-node-set > > (xpath-sys:make-pipe (car value-list) (cdr > > value-list)))))) > > sorry for the late reply. No problem, thanks. > I suspect that by now you might have come up > with a solution yourself, so I'll keep my answer brief for now: > > I think you need to return a set of nodes, whereas you have a set of > strings, and a string as such isn't a node. > > If the above is too obscure, please let me know, and I'll elaborate! :-) It's not too obscure - but I'm still not shure how to achive my goal. I'm looking for a public api to generate nodes. So far I've found (dom:create-text-node doc data) but that leaves me with two questions: first, from within a xpath extension function there's no obvious way to access the document being processed (I might be missing something here but I _think_ the xpath api should provide more context). Second: dom:create-... isn't really a good match for xpath since one can't create some of the xpath node types (booleans, numbers etc.). Somehow I feel this is more of a xpath api problem but maybe you have some idea/input on this. Thanks RalfD > > d. > > _______________________________________________ > xuriella-devel mailing list > xuriella-devel at common-lisp.net > http://lists.common-lisp.net/cgi-bin/mailman/listinfo/xuriella-devel From rwiker at gmail.com Sun May 20 17:47:27 2012 From: rwiker at gmail.com (Raymond Wiker) Date: Sun, 20 May 2012 19:47:27 +0200 Subject: [xuriella-devel] Question concerning custom xpath functions returning node sets In-Reply-To: <20120520174518.GB19722@seid-online.de> References: <20120508192505.M67880@mh-freiburg.de> <20120520143929.GB12273@radon> <20120520174518.GB19722@seid-online.de> Message-ID: <53EEBDF6-646F-4CE4-82DE-E7A4D05D396C@gmail.com> On May 20, 2012, at 19:45 , rm at tuxteam.de wrote: > It's not too obscure - but I'm still not shure how to achive my goal. > I'm looking for a public api to generate nodes. So far I've found > (dom:create-text-node doc data) but that leaves me with two questions: > first, from within a xpath extension function there's no obvious way to > access the document being processed (I might be missing something here > but I _think_ the xpath api should provide more context). > Second: dom:create-... isn't really a good match for xpath since one > can't create some of the xpath node types (booleans, numbers etc.). > > Somehow I feel this is more of a xpath api problem but maybe you > have some idea/input on this. I'm not 100% sure, but the function you're looking for may be cxml-stp:make-text... possibly in conjunction with xpath:make-node-set. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rm at tuxteam.de Sun May 20 18:23:19 2012 From: rm at tuxteam.de (rm at tuxteam.de) Date: Sun, 20 May 2012 20:23:19 +0200 Subject: [xuriella-devel] Question concerning custom xpath functions returning node sets In-Reply-To: <53EEBDF6-646F-4CE4-82DE-E7A4D05D396C@gmail.com> References: <20120508192505.M67880@mh-freiburg.de> <20120520143929.GB12273@radon> <20120520174518.GB19722@seid-online.de> <53EEBDF6-646F-4CE4-82DE-E7A4D05D396C@gmail.com> Message-ID: <20120520182319.GC19722@seid-online.de> On Sun, May 20, 2012 at 07:47:27PM +0200, Raymond Wiker wrote: > On May 20, 2012, at 19:45 , rm at tuxteam.de wrote: > > It's not too obscure - but I'm still not shure how to achive my goal. > > I'm looking for a public api to generate nodes. So far I've found > > (dom:create-text-node doc data) but that leaves me with two questions: > > first, from within a xpath extension function there's no obvious way to > > access the document being processed (I might be missing something here > > but I _think_ the xpath api should provide more context). > > Second: dom:create-... isn't really a good match for xpath since one > > can't create some of the xpath node types (booleans, numbers etc.). > > > > Somehow I feel this is more of a xpath api problem but maybe you > > have some idea/input on this. > > I'm not 100% sure, but the function you're looking for may be cxml-stp:make-text... possibly in conjunction with xpath:make-node-set. No, that's pretty much the same (api-wise) as dom:create-text-node ...). Well, for this special case I wouldn't need a document instance, so stp would be a workarround to be used in xpath functions. But it feels wrong to use a implementation-specific api for my task. And it stil won't be a general way to return node-sets of booleans or numbers. Thanks RalfD P.S.: I think the issue here is that xpath view of xml documents isn't the same as xml/dom's .... From david at lichteblau.com Sun May 20 18:03:59 2012 From: david at lichteblau.com (David Lichteblau) Date: Sun, 20 May 2012 20:03:59 +0200 Subject: [xuriella-devel] Question concerning custom xpath functions returning node sets In-Reply-To: <20120520182319.GC19722@seid-online.de> References: <20120508192505.M67880@mh-freiburg.de> <20120520143929.GB12273@radon> <20120520174518.GB19722@seid-online.de> <53EEBDF6-646F-4CE4-82DE-E7A4D05D396C@gmail.com> <20120520182319.GC19722@seid-online.de> Message-ID: <20120520180359.GC12273@radon> Quoting rm at tuxteam.de (rm at tuxteam.de): > No, that's pretty much the same (api-wise) as dom:create-text-node ...). > Well, for this special case I wouldn't need a document instance, so stp > would be a workarround to be used in xpath functions. But it feels wrong > to use a implementation-specific api for my task. And it stil won't be > a general way to return node-sets of booleans or numbers. > > Thanks RalfD > > P.S.: I think the issue here is that xpath view of xml documents isn't > the same as xml/dom's .... I'm actually not entirely certain how I would approach this task if it came up in my code. But I suspect I might use (or make up) my very own objects (independently of dom or stp, suited to the needs of the application) and define the appropriate methods on generic functions in the xpath-protocol package to inform xpath about how to understand those objects. (This protocol is possibly as not well documented as it ought to be, but is meant to be user-visible and supported.) d. From rm at tuxteam.de Sun May 20 18:50:27 2012 From: rm at tuxteam.de (rm at tuxteam.de) Date: Sun, 20 May 2012 20:50:27 +0200 Subject: [xuriella-devel] Question concerning custom xpath functions returning node sets In-Reply-To: <20120520180359.GC12273@radon> References: <20120508192505.M67880@mh-freiburg.de> <20120520143929.GB12273@radon> <20120520174518.GB19722@seid-online.de> <53EEBDF6-646F-4CE4-82DE-E7A4D05D396C@gmail.com> <20120520182319.GC19722@seid-online.de> <20120520180359.GC12273@radon> Message-ID: <20120520185027.GD19722@seid-online.de> On Sun, May 20, 2012 at 08:03:59PM +0200, David Lichteblau wrote: > Quoting rm at tuxteam.de (rm at tuxteam.de): > > No, that's pretty much the same (api-wise) as dom:create-text-node ...). > > Well, for this special case I wouldn't need a document instance, so stp > > would be a workarround to be used in xpath functions. But it feels wrong > > to use a implementation-specific api for my task. And it stil won't be > > a general way to return node-sets of booleans or numbers. > > > > Thanks RalfD > > > > P.S.: I think the issue here is that xpath view of xml documents isn't > > the same as xml/dom's .... > > I'm actually not entirely certain how I would approach this task if it > came up in my code. > > But I suspect I might use (or make up) my very own objects > (independently of dom or stp, suited to the needs of the application) > and define the appropriate methods on generic functions in the > xpath-protocol package to inform xpath about how to understand those > objects. (This protocol is possibly as not well documented as it ought > to be, but is meant to be user-visible and supported.) O.k. - but while that seems possible to solve "my" problem, but since pp-xpath provides an api to extend its functionality I'd expect there to be a way to return xpath types from those functions. It seems redundant for each extension to design/implement a exptension-specific object system. So I'd expect something like (xpath:to-node 42) etc. Or even (xpath-sys:make-node-set (list 3 4 5 6) :unordered) Cheers, RalfD > > d. > > _______________________________________________ > xuriella-devel mailing list > xuriella-devel at common-lisp.net > http://lists.common-lisp.net/cgi-bin/mailman/listinfo/xuriella-devel From rm at tuxteam.de Sun May 20 18:53:14 2012 From: rm at tuxteam.de (rm at tuxteam.de) Date: Sun, 20 May 2012 20:53:14 +0200 Subject: [xuriella-devel] cxml-stp -> kaboom! In-Reply-To: <20120520180359.GC12273@radon> References: <20120508192505.M67880@mh-freiburg.de> <20120520143929.GB12273@radon> <20120520174518.GB19722@seid-online.de> <53EEBDF6-646F-4CE4-82DE-E7A4D05D396C@gmail.com> <20120520182319.GC19722@seid-online.de> <20120520180359.GC12273@radon> Message-ID: <20120520185314.GE19722@seid-online.de> Btw, just stumbled over this: | | (ql:quickload "cxml-stp") | | (cxml-stp:make-text "42") | | #.(CXML-STP:TEXT :DATA "42") | | (cxml-stp:make-text 42) | CORRUPTION WARNING in SBCL pid 18045(tid 3084887728): | Memory fault at a5 (pc=0xb6e8f14, sp=0xb78869c8) | The integrity of this image is possibly compromised. | Continuing with fingers crossed. | | debugger invoked on a SB-SYS:MEMORY-FAULT-ERROR in thread | #: | Unhandled memory fault at #xA5. | | Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL. | | restarts (invokable by number or by possibly-abbreviated name): | 0: [ABORT] Exit debugger, returning to top level. | | (SB-SYS:MEMORY-FAULT-ERROR) | | I knew I shouldn't do this but I didn't expect a segfault .... Cheers, RalfD