<!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.7 2004/08/04 16:30:59 goba 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")

;; Generate anchor for elements without an ID
;; 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))
	)
)

;; Quotes a string to be inserted to a single quoted string
(define (phpweb-quote str)
	(string-replace str "'" "\\'")
)

;; Prints out a PHP file header. Parameter is the current node (unused)
(define (phpweb-header #!optional (nd (current-node)))
	(php-code
		(string-append
			newline
			"include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';"
			newline
			(phpweb-page-setup nd) newline
			"manual_header();" newline
		)
	)
)

;; Prints out manual footer PHP code. Parameter is the current node (unused)
(define (phpweb-footer #!optional (nd (current-node)))
	(php-code
		(string-append
			"manual_footer();" newline
		)
	)
)

;; Retrieves a node's title from the XML source. Parameters are
;; the current node and title element's name (unused)
(define (phpweb-node-title #!optional (nd (current-node)) (title-elem "title"))
	(let*
		(
			(preferred-title-node
				(cond
					;; For "refentry"s search for the first (and only one)
					;; "refname" from the children list of "refnamediv" childrens.
					(
						(equal? (gi nd) "refentry")
							(node-list-first
								(select-elements
									(children
										(select-elements (children nd) "refnamediv")
									)
									"refname"
								)
							)
						)
					;; For other nodes, just select the first children node
					(else
						(node-list-first
							(select-elements (children nd) title-elem)
						)
					)
				)
			)
			;; The title node is the preferred title node, or if
			;; it cannot be find, then then "title" children
			(title-node
				(if (node-list-empty? preferred-title-node)
					(select-elements (children nd) "title")
					preferred-title-node
				)
			)
		)
		(data title-node)
	)
)
	       
;; Prints out the navigational array. Considers that the array was
;; needed (home, prev, next, up, toc) or not needed (local TOC).
;; In the later case, nothing should be printed, in the first
;; case, an emty array need to be injected. For local TOC
;; entries, text should be indented with 4 spaces.
;; Parameters are the node and a #t/#f value indicating that the
;; array is a main navigation array [#t]or local TOC array [#f].
(define (phpweb-header-nav-array nd main_nav_array)
	(let 
		(
			(href (href-to nd))
			(title (phpweb-quote (phpweb-node-title nd "titleabbrev")))
		)
		(if (string=? title "")
			(if main_nav_array
				(string-append "array('', '')," newline)
				""
			)
			(if main_nav_array
				(string-append "array('" href "', '" title "')," newline)
				(string-append "    array('" href "', '" title "')," newline)
			)
		)
	)
)
   
;; Returns a list of strings as provided by the "func" function
;; parameterized with the "node" node. Parameters are the function
;; to use for mapping and the node list on which to apply the mapping
(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))
		)
	)
)

;; Defines the header navigation with PHP calls to set up the
;; navigation array used by TOC printer functions. Parameter is
;; the current node.
(define (phpweb-page-setup 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
			"manual_setup(array(" newline
			"  'head' => array('@ENCODING@', '@LANGWEB@')," newline
			"  'home' => " (phpweb-header-nav-array home #t)
			"  'this' => array('" (phpweb-quote (html-base-filename nd))
			"', '" (phpweb-quote (phpweb-node-title nd)) "')," newline
			"  'prev' => " (phpweb-header-nav-array prev #t)
			"  'next' => " (phpweb-header-nav-array next #t)
			"  'up'   => " (phpweb-header-nav-array up #t)
			"  'toc'  => array(" newline
			(join
				(phpweb-node-list-map 
					(lambda
						(nnl)
						(phpweb-header-nav-array nnl #f)
					)
					toc-nodes
				)
			)
			")));"
		)
	)
)
    
;; Defines the format of all the output files
;; generated for phpweb display. Parameters are the
;; title sequence and the body sequence.
(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:
-->
