chickadee » sxpath » sxml:id-alist

sxml:id-alist node #!rest lpathsprocedure

Builds an index as a list of (ID_value . element) pairs for given node. lpaths are location paths for attributes of type ID (ie, sxpath expressions that tell it how to find the ID attribute).

Note: location paths must be of the form (expr '@ attrib-name).

See also sxml:lookup below, in sxpath-lolevel, which can use this index.

;; Obtain ID values for a regular XHTML DOM
(sxml:id-alist
 '(div (h1 (@ (id "info"))
           "A story")
       (p (@ (id "story-body"))
	  "Once upon a time")
       (a (@ (id "back") (href "../index.xml"))
	  "click here to go back"))
 '(* @ id))
 => (("info" h1 (@ (id "info")) "A story")
     ("story-body" p (@ (id "story-body")) "Once upon a time")
     ("back" a (@ (id "back") (href "../index.xml")) "click here to go back"))

;; In an alternate reality, where links are uniquely identified
;; by their href, we would use this
(sxml:id-alist
 '(div (h1 (@ (id "info"))
	   "A story")
       (p (@ (id "story-body"))
	  "Once upon a time")
       (a (@ (id "back") (href "../index.xml"))
	  "click here to go back"))
 '(h1 @ foo) '(a @ href))
 => (("../index.xml" . (a (@ (id "back")
                             (href "../index.xml"))
                          "click here to go back")))