<!DOCTYPE style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN" [
<!ENTITY docbook.dsl SYSTEM "@DOCBOOK_HTML@" CDATA DSSSL>
<!ENTITY html-common.dsl SYSTEM "@srcdir@/html-common.dsl">
<!ENTITY common.dsl SYSTEM "common.dsl">
<!ENTITY version.dsl SYSTEM "@srcdir@/version.dsl">
]>

<!--

  $Id: phpweb.dsl.in,v 1.1 2002/01/06 15:42:27 hholzgra Exp $

  HTML-specific stylesheet customization for use by the online manual.

-->

<style-sheet>
<style-specification id="docbook-php-website" use="docbook">
<style-specification-body>

(declare-flow-object-class processing-instruction
  "UNREGISTERED::James Clark//Flow Object Class::processing-instruction")

(define %html-ext% ".php")
(define %html-manifest% "PHPWEB.manifest")
(define %output-dir% "php")

;; XXX hackish workaround.  I'm not sure what side effects setting
;; the element number to 0 would have?
(define (generate-anchor #!optional (nd (current-node)))
  (string-append "AEN" (number->string (or (all-element-number nd) 0))))

(define (phpweb-quote str)
  (string-replace str "'" "\\'"))

(define (phpweb-header #!optional (nd (current-node)))
    (php-code
     (string-append
      newline
      "require('shared-manual.inc');" newline
      "sendManualHeaders('@ENCODING@','@LANG@');" newline
      (phpweb-header-navigation nd) newline
      "manualHeader('" (phpweb-quote (phpweb-node-title nd)) "','" (phpweb-quote (html-base-filename nd)) "');" newline)))

(define (phpweb-footer #!optional (nd (current-node)))
  (php-code
   (string-append
    "manualFooter('" (phpweb-quote (phpweb-node-title nd)) "','" (phpweb-quote (html-base-filename nd)) "');" newline)))

(define (phpweb-node-title #!optional (nd (current-node)) (title-elem "title"))
  (let* ((preferred-title-node
	  (cond ((equal? (gi nd) "refentry")
		 (node-list-first
		  (select-elements
		   (children
		    (select-elements (children nd) "refnamediv"))
		   "refname")))
		(else
		 (node-list-first
		  (select-elements (children nd) title-elem)))))
	 (title-node
	  (if (node-list-empty? preferred-title-node)
	      (select-elements (children nd) "title") ;; fallback
	      preferred-title-node)))
    (data title-node)))
	       
(define (phpweb-header-nav-array nd)
  (let ((href (href-to nd))
	(title (phpweb-quote (phpweb-node-title nd "titleabbrev"))))
    (string-append
     "array('" href "', '" title "')")))
   
(define (phpweb-node-list-map func ndl)
  (let* ((node (node-list-first ndl))
	 (rest (node-list-rest ndl))
	 (item (func node)))
    (if (node-list-empty? rest)
	(list item)
	(append (list item) (phpweb-node-list-map func rest)))))

(define (phpweb-header-navigation nd)
  (let ((prev (prev-chunk-element nd))
	(next (next-chunk-element nd))
	(up (parent nd))
	(home (sgml-root-element))
	(toc-nodes (siblings (chunk-parent nd))))
    (string-append
     "setupNavigation(array(" newline
     "  'home' => " (phpweb-header-nav-array home) "," newline
     "  'prev' => " (phpweb-header-nav-array prev) "," newline
     "  'next' => " (phpweb-header-nav-array next) "," newline
     "  'up'   => " (phpweb-header-nav-array up) "," newline
     "  'toc'  => array(" newline
     (join 
      (phpweb-node-list-map (lambda (nnl)
			      (string-append
			       "    "
			       (phpweb-header-nav-array nnl)))
			    toc-nodes)
      (string-append "," newline))
     ")));")))
    
(define (html-document title-sosofo body-sosofo)
  (let ((doc-sosofo 
	 (if (or (chunk?) (node-list=? (current-node) (sgml-root-element)))
	     (make sequence
		   (phpweb-header (current-node))
		   body-sosofo
		   (phpweb-footer (current-node)))
	     body-sosofo)))
    (if (chunk?)
	(make entity
	      system-id: (html-entity-file (html-file))
	      doc-sosofo)
	doc-sosofo)))

&html-common.dsl;
&common.dsl;
&version.dsl;

</style-specification-body>
</style-specification>
<external-specification id="docbook" document="docbook.dsl">
</style-sheet>

<!--
Local Variables:
mode: scheme
End:
-->
