Mulberry home page

DSSSList Archive

Mulberry Home Page
DSSSL
DSSSList
Archive
Previous by Date
Next by Date
Previous by Thread
Next by Thread
Index by Thread
Index by Date
Index by Subject
Index by Author
Search

Re: Sibling rivalry

From: James Clark <[email protected]>
Date: Mon, 31 Mar 1997 10:35:50 +0700
At 18:10 30/03/97 -0800, Jon Bosak wrote:
>I'm formatting the latest version of the XML spec and have hit a wall
>in handling the productions.

I don't think you can do this in the core query language, but Jade provides
enough of the full query language that you can handle it.  For PROD, instead
of just calling process-children, loop over the children explicitly and
group together adjacent elements that need to go in a single table-cell.
This relies on node-list-first, node-list-rest and process-node-list.

(element PROD
	 (make table
	       (make table-column
		     width: 2pi)
	       (make table-column
		     width: 7pi)
	       (make table-column
		     width: 1.5pi)
	       (make table-column
		     width: 16.5pi)
	       (make table-column
		     width: 9pi)
	       (process-prod (children (current-node)))))

(define (process-prod nl)
  (if (node-list-empty? nl)
      (empty-sosofo)
      (let ((nd (node-list-first nl)))
	(case (gi nd)
	  (("LHS" "RHS")
	   (sosofo-append
	    (process-node-list nd)
	    (process-prod (node-list-rest nl))))
	  ((#f)
	   (process-prod (node-list-rest nl)))
	  (else
	   (let loop ((info '())
		      (nl nl))
	     (if (node-list-empty? nl)
		 (pinfo (reverse info))
		 (let ((nd (node-list-first nl)))
		   (if (equal? (gi nd) "RHS")
		       (sosofo-append
			(pinfo (reverse info))
			(process-prod nl))
		       (loop (cons nd info)
			     (node-list-rest nl)))))))))))
	   
(define (pinfo lst)
  (make table-cell
	column-number: 5
	(let loop ((lst lst))
	  (if (null? lst)
	      (empty-sosofo)
	      (sosofo-append
	       (process-node-list (car lst))
	       (loop (cdr lst)))))))
		 
(element LHS
	 (sosofo-append
	  (make table-cell
		column-number: 1
		font-weight: 'bold
		(make paragraph
		      use: para-style
		      start-indent: 0pt
		      font-weight: 'bold
		      (literal
		       (string-append
			"["
			(number->string (element-number (ancestor "PROD")))
			"]"))))
	  (make table-cell
		column-number: 2
		(make paragraph
		      use: monopara-style
		      font-weight: 'bold
		      (process-children-trim)))
	  (make table-cell
		column-number: 3
		(make paragraph
		      start-indent: 0pt
		      (literal ":=")))))

(element RHS
	 (make table-cell
	       starts-row?: (not (first-sibling?))
	       column-number: 4
	       n-columns-spanned: (if (absolute-last-sibling?) 2 1)
	       (make paragraph
		     use: monopara-style
		     (process-children-trim))))

(element COM
	 (make paragraph
	       use: para-style
	       font-posture: 'italic
	       start-indent: 0pt
	       (sosofo-append
		(literal "/* ")
		(process-children-trim)
		(literal " */"))))

(element VC ($vc-wfc$ "VC"))
(element WFC ($vc-wfc$ "WFC"))

(define ($vc-wfc$ vc-or-wfc)
  (make paragraph
	font-family-name: %title-font-family%
	font-size: 9pt
	start-indent: 1pi
	first-line-start-indent: -1pi
	(sosofo-append
	 (literal
	  (string-append "[" vc-or-wfc ": "))
	 (process-children-trim)
	 (literal "]"))))

James