DD: Cookbook procedure markup sample (Was: DD: Status)

Subject: DD: Cookbook procedure markup sample (Was: DD: Status)
From: Tony Graham <tgraham@xxxxxxxxxxxxxxxx>
Date: Wed, 2 Jul 1997 12:22:34 -0400 (EDT)
At 2 Jul 1997 00:03 -0400, Tony Graham wrote:
 > 3. There were calls last week for a place to host "library-like
 >    stuff".  I volunteered to host the "DSSSL Cookbook" of tips and
 >    techniques as part of the documentation effort.  Taking the
 >    subsequent silence as approval, please send me your reusable
 >    procedures or implementations of procedures defined in the
 >    standard (marked up using DocBook 3.0 if possible).

The remainder of this message is sample markup of some procedures
plucked from DSSSList postings from the last week or so.  If each
procedure is marked up as a separate <sect2> using <programlisting>
for the DSSSL code and using <para>, etc., for whatever explanation is
necessary, then we can fit the <sect2>s into the overall structure of
the Cookbook.

This sample formats quite nicely using Norman Walsh's DocBook
stylesheet, although it should also be possible to customize that
stylesheet to output author's names (and to reduce the program
listing font size).

Regards,


Tony Graham
=======================================================================
Tony Graham, Consultant
Mulberry Technologies, Inc.                         Phone: 301-231-6931
6010 Executive Blvd., Suite 608                     Fax:   301-231-6935
Rockville, MD USA 20852                 email: tgraham@xxxxxxxxxxxxxxxx
=======================================================================

<!DOCTYPE chapter PUBLIC "-//Davenport//DTD DocBook V3.0//EN">
<!-- $Id: cb-sample.sgm,v 1.1 1997/07/02 11:22:45 tkg Exp $ -->
<chapter>
<title>Cookbook Procedures Sample</title>
<para>The procedures are shown as a separate chapter to leave room for other sorts of material in other chapters.</para>
<para>This sample shows only two sections within the chapter, but it could contain as many as there are useful divisions to be made.</para>
<para>These samples are short on descriptions of their use or of their requirements, but it is possible to include as much commentary as you feel is necessary.</para>
<sect1>
<title>Procedures Defined In The DSSSL Standard</title>
<para>These are implementations of procedures defined in the DSSSL standard but which may not yet be built-in for a particular tool.</para>
<sect2>
<sect2info>
<author>
<firstname>Tony</firstname><surname>Graham</surname>
</author>
<revhistory>
<revision>
<revnumber>1.0</revnumber>
<date>19970701</date>
<authorinitials>Tony Graham tgraham@xxxxxxxxxxxxxxxx</authorinitials>
<revremark>Sample copied from David Megginson's DSSSList post of 19970624</revremark>
</revision>
</revhistory>
</sect2info>
<title>children</title>
<para>This will work only with elements (and not the root element, at that).</para>
<programlisting>(define (siblings snl)
  (children (parent snl)))</programlisting>
</sect2>
<sect2>
<sect2info>
<author>
<firstname>Tony</firstname><surname>Graham</surname>
</author>
<revhistory>
<revision>
<revnumber>1.0</revnumber>
<date>19970701</date>
<authorinitials>Tony Graham tgraham@xxxxxxxxxxxxxxxx</authorinitials>
<revremark>Sample copied from Vivek Agrawala's DSSSList post of 19970627</revremark>
</revision>
</revhistory>
</sect2info>
<title>ipreced</title>
<programlisting>(define (ipreced nl)
  (node-list-map (lambda (snl)
		   (let loop ((prev (empty-node-list))
			      (rest (siblings snl)))
		     (cond ((node-list-empty? rest)
			    (empty-node-list))
			   ((node-list=? (node-list-first rest) snl)
			    prev)
			   (else
			    (loop (node-list-first rest)
				  (node-list-rest rest))))))
		 nl))</programlisting>
</sect2>
<sect2>
<sect2info>
<author>
<firstname>Tony</firstname><surname>Graham</surname>
</author>
<revhistory>
<revision>
<revnumber>1.0</revnumber>
<date>19970701</date>
<authorinitials>Tony Graham tgraham@xxxxxxxxxxxxxxxx</authorinitials>
<revremark>Sample copied from Vivek Agrawala's DSSSList post of 19970627</revremark>
</revision>
</revhistory>
</sect2info>
<title>match-element?</title>
<programlisting>(define (match-element? pattern snl)
  (if (node-list-empty? (select-elements snl pattern)) #f #t) )</programlisting>
</sect2>
</sect1>
<sect1>
<title>Other Useful Procedures</title>
<para>These are other procedures that people have found useful and want to share with other DSSSL users.
<sect2>
<sect2info>
<author>
<firstname>Tony</firstname><surname>Graham</surname>
</author>
<revhistory>
<revision>
<revnumber>1.0</revnumber>
<date>19970701</date>
<authorinitials>Tony Graham tgraham@xxxxxxxxxxxxxxxx</authorinitials>
<revremark>Sample copied from Vivek Agrawala's DSSSList post of 19970627</revremark>
</revision>
</revhistory>
</sect2info>
<title>absolute-child-number</title>
<programlisting>;; -- Similar to child-number, but also counts siblings with a GI
;; -- different than that of 'snl'.
(define (absolute-child-number snl)
  (+ 1 (node-list-length (preced snl))) )</programlisting>
</sect2>
<sect2>
<sect2info>
<author>
<firstname>Tony</firstname><surname>Graham</surname>
</author>
<revhistory>
<revision>
<revnumber>0.1</revnumber>
<date>19970702</date>
<authorinitials>Tony Graham tgraham@xxxxxxxxxxxxxxxx</authorinitials>
<revremark>Sample copied from Vivek Agrawala's DSSSList post of 19970627</revremark>
</revision>
</revhistory>
</sect2info>
<title>has-child?</title>
<programlisting>;; -- Does 'snl' have a child with GI 'gi'.
(define (has-child? gi snl)
  (not (node-list-empty? (select-elements gi (children snl)))) )</programlisting>
</sect2>
<sect2>
<sect2info>
<author>
<firstname>Tony</firstname><surname>Graham</surname>
</author>
<revhistory>
<revision>
<revnumber>1.0</revnumber>
<date>19970701</date>
<authorinitials>Tony Graham tgraham@xxxxxxxxxxxxxxxx</authorinitials>
<revremark>Sample copied from Vivek Agrawala's DSSSList post of 19970627</revremark>
</revision>
</revhistory>
</sect2info>
<title>substitute-char</title>
<programlisting>;; -- In 'str', substitute all occurences of 'old-char' with 'new-char'.
(define (substitute-char str old-char new-char)
  (let ( (n (string-length str)) )
    (let loop ( (i 0) (newstr "") )
      (cond
        ( (< i n)  (loop (+i 1) (string-append newstr (string
             (if (equal? (string-ref str i) old-char)
                   new-char
                   (string-ref str i) )))))

        ( (equal? i n)  newstr ) ))))</programlisting>
</sect2>
</sect1>
</chapter>


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


Current Thread
  • DD: Status
    • Tony Graham - Wed, 2 Jul 1997 00:00:45 -0400 (EDT)
      • Tony Graham - Wed, 2 Jul 1997 12:19:35 -0400 (EDT) <=
        • Dave Love - Wed, 2 Jul 1997 18:07:41 -0400 (EDT)
          • Tony Graham - Wed, 16 Jul 1997 06:43:24 -0400 (EDT)
          • Dave Love - Thu, 31 Jul 1997 12:33:46 -0400 (EDT)
          • Tony Graham - Thu, 17 Jul 1997 23:16:43 -0400 (EDT)