Hi,<br><br>In the course of using my little xpath contribution, I've come up with a few macros that make life easier.<br><br><br>(defmacro ?> (xpath doc)<br> "Execute the specified xpath on doc. If the result is a list of length 1, make it an atom.<br>
`(let ((rslt (funcall (sxpath ,xpath) ,doc)))<br> (if (second rslt)<br> rslt<br> (car rslt))))<br><br>(defmacro ?let (bindings &body body)<br> "Bind names to xpaths in bindings. Each name then refers to a function that takes as its<br>
argument an sxml node and returns the result of executing the specified xpath on that node"<br> (with-gensyms (doc)<br> `(labels ,(loop for (name xpath) in bindings<br> collect `(,name (,doc)<br>
(?> ,xpath ,doc)))<br> ,@body)))<br><br>(defmacro with-attrs (bindings node &body body)<br> "Convenience function to make the specified attributes available. Works like with-accessors<br>
but for xml attributes"<br> `(let ,(loop for (name attr) in bindings<br> collect `(,name (cadr (?> '(:@ ,attr) ,node))))<br> ,@body))<br><br>;; Note that the second one requires the macro `with-gensyms' (included below for convenience)<br>
<br>(defmacro with-gensyms ((&rest names) &body body)<br>
`(let ,(loop for n in names collect `(,n (gensym)))<br>
,@body))<br><br><br>;;<br>;Andy<br>
<br><br>