First-such-xref

First Such Xref

Christopher Maden

(first-such-xref snl) returns the first DocBook xref in the current container to refer to the same target as snl.

(define (first-such-xref #!optional (snl (current-node)))
  (node-list-first (node-list-filter (lambda (candidate)
                                       (equal? (attribute-string (norm "linkend")
                                                                 candidate)
                                               (attribute-string (norm "linkend")
                                                                 snl)))
                                     (descendants (if (node-list-empty? (ancestor (norm "preface")
                                                                                  snl))
                                                      (if (node-list-empty? (ancestor (norm "chapter")
                                                                                      snl))
                                                          (if (node-list-empty? (ancestor (norm "appendix")
                                                                                          snl))
                                                              (error "Where am I?")
                                                              (ancestor (norm "appendix")
                                                                        snl))
                                                          (ancestor (norm "chapter")
                                                                    snl))
                                                      (ancestor (norm "preface")
                                                                snl))))))