Another method uses the 'ref' function:
Code: Select all
(set 'mc '(media:content
    (@
      (url "http://graphics8.nytimes.com/images/.../thumbStandard.jpg") 
      (medium "image") 
      (height "75") 
      (width "75"))))
(last (mc (ref '(url *) mc match))) 
;=> "http://graphics8.nytimes.com/.../thumbStandard.jpg"
The advantage here is, that 'ref' reaches into all nesting levels of a list. The above solution wouldn't need to change if the structure of the XML changes. As long as there is an (url *) elelement in it, 'ref' will find it.
'ref-all' is a version of 'ref' which returns all index vectors found, not only the first one:
Code: Select all
(set 'mc '(( x y z (url "A.com")) (q ( z (url "B.com"))) (url "C.com")))
(set 'vectors (ref-all '(url *) mc match)) ;=> ((0 3) (1 1 1) (2))
(map last (map 'mc vectors)) ;=> ("A.com" "B.com" "C.com")
What few people know is, that indexing a list also can be mapped by mapping the data structure like a function on to the list of indexes. In this case 'mc' is an complex nested data structure with all urls on a different level, but all are found. Note that 'mc' must be quoted in the mapping expression.