(dsssl) Re: If no P children?

Subject: (dsssl) Re: If no P children?
From: Tim McDaniel <tmcd@xxxxxxxxx>
Date: Sun, 16 Mar 2003 03:46:39 -0600 (CST)
(By the way, I apologize if I use incorrect terminology.  I know
little about XML and DSSSL.)

On Sun, 16 Mar 2003, Tim McDaniel <tmcd@xxxxxxxxx> wrote:
>         (make element gi: "dd"
>               (if ANY DESCENDANT OF THIS ITEM IS A <P>
>                   (process-matching-children 'discussion
>                   (literal "&nbsp;")
>               ) ;; make element dd

I found a way.

I used "our-" as a prefix just to avoid namespace collisions.  Perhaps
a better name for "our-has?" is "node-list-some-recursive?".  Since
"our-is-p?" was used in just one place, I could have made it a lambda
expression, but I don't usually get that LISPy.  I could have
generalized it more, by writing a "node-list-reduce-recursive"
function and then use that for this.

    (define (our-is-p? node) (match-element? '(p) node))

    ;; our-has?: #t if proc is true for any member of nl or its
    ;; descendents, #f otherwise.
    ;; It does a depth-first search, applying proc to each element it gets
    ;; to.  It returns #t as soon as proc returns a true value for something.
    (define (our-has? proc nl)
      (if (node-list-empty? nl)
          #f
          (if (proc (node-list-first nl))
              #t
              (if (our-has? proc (children (node-list-first nl)))
                  #t
                  (our-has? proc (node-list-rest nl))
                  )
              )
          )
      )

Then the test is

          (if (our-has? our-is-p? (current-node))
              (process-matching-children 'discussion)
              (literal "&#160;")
              )
          ) ;; make element DD

I first tried
              (literal "&nbsp;")

Jade complained that it didn't recognize the "nbsp" entity.  I
replaced it with the numeric entity as above, and it puts in an octal
240 character -- I guess Jade replaced that entity at compile time, as
it were.  Filled with hope that I might be able to answer another of
my own questions (how do I insert a literal newline?), I tried
              (literal "&#010;&#010;&#160;&#010;&#010;")
Alas, it stripped the newlines.

-- 
Tim McDaniel (home); Reply-To: tmcd@xxxxxxxxx; work is tmcd@xxxxxxxxxxx

 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist

Current Thread