Re: Node list notation for examples

Subject: Re: Node list notation for examples
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxx>
Date: Wed, 05 Nov 1997 11:46:12 -0500
At 11:28 97/11/05 -0500, Tony Graham wrote:
>Does anybody have a good notation for representing node lists when
>making examples of how to use DSSSL procedures?

I can't claim it is "good" because it would never parse as a valid DSSSL
node list, but I use the following to document node lists, for example
regarding ancestry:

'{{"DOC"} {"PARA"}}

or an empty node list:

'{}

where the information inside the brace brackets is flexible depending on
the information I want to relate about the node, in this case the generic
identifier in quotes.

I chose to use this based on existing DSSSL syntax.  Remember in DSSSL to
specify a fixed-value list, say of numbers, one would use:

'(1 2 3)

Or a list of two lists:

'((1 2 3) ("A" "B" "C"))

Or a list of lists of two strings (used with the SGML back end).

(define body-attrs '( ("bgcolor" "white") ("text" "black") ("link" "black")
                      ("vlink" "black") ("alink" "black") ) )

Or an empty list:

'()

It was important for me to choose something that would not be used
successfully in a program, which if it was successfully parsed, would cause
grief from someone trying to use the syntax and finding the engine not
complaining.  If someone tries to use my node list syntax actually in a
program as an argument to a function call requiring a node list, the DSSSL
engine will prevent the program from running cleanly:

C:\PROGRA~1\JADE\CURRENT\JADE.EXE:test2.dsl:31:23:E: 1st argument for
primitive "node-list-length" of wrong type: "{{" not a node list

Unfortunately, this syntax for an empty node list is valid DSSSL syntax as
(symbol->string '{}) returns the string "{}", so if it isn't used as an
argument to a function it may slip by.  I suppose one could skip using the
single quote, but I wanted the similarity to a valid list to be there.

When I wanted to examine a node list once, I wrote something along the
lines of the example copied below ... the end result meant something to me
when I wrote it elsewhere, so I have adopted it as a personal convention.

The following shows me that the "(ancestors" function returns the nodes in
the order from the root down to the element (which wasn't what I was
expecting; I was expecting from current node up to the root).

.................. Ken


F:\FTEMP>type test.dsl
<!DOCTYPE style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN">

(define (ancestors nl)
  (node-list-map (lambda (snl)
                   (let loop ((cur (parent snl))
                              (result (empty-node-list)))
                     (if (node-list-empty? cur)
                         result
                         (loop (parent cur)
                               (node-list cur result)))))
                 nl))

(default                       ;handle all elements not explicitly handled
    (let loop ((l (ancestors (current-node)))
               (s (string-append (gi (current-node)) ": '{")))
        (if (node-list-empty? l)
            (sosofo-append
                (literal (string-append s "}"))
                (process-children))
            (loop (node-list-rest l)
                  (string-append s " {\"" (gi (node-list-first l)) "\"}" )))))

; end of file

F:\FTEMP>type test.sgm
<!DOCTYPE doc [
<!ELEMENT doc - O (para+)>
<!ELEMENT para - O ( #PCDATA | thing )+>
<!ELEMENT thing - O ( #PCDATA )>
]>
<doc>
<para>hello
<para>world<thing>trigger
<para>goodbye



F:\FTEMP>jade -c l:\jade\current\catalog -d test.dsl test.sgm

F:\FTEMP>type test.fot
<!doctype fot public "-//James Clark//DTD DSSSL Flow Object Tree//EN">
<element index=0 rule-default>
<chars>
DOC: '{}
</chars>
<element index=1 rule-default>
<chars>
PARA: '{ {"DOC"}}
</chars>
<chars>
hello
</chars>
</element>
<element index=2 rule-default>
<chars>
PARA: '{ {"DOC"}}
</chars>
<chars>
world
</chars>
<element index=3 rule-default>
<chars>
THING: '{ {"DOC"} {"PARA"}}
</chars>
<chars>
trigger
</chars>
</element>
</element>
<element index=4 rule-default>
<chars>
PARA: '{ {"DOC"}}
</chars>
<chars>
goodbye

</chars>
<chars>


</chars>
</element>
</element>

F:\FTEMP>



--
G. Ken Holman            mailto:gkholman@xxxxxxxxxxxxxx
Crane Softwrights Ltd.  http://www.CraneSoftwrights.com
1605 Mardick Court, Box 266,         V: +1(613)489-0999
Kars, Ontario CANADA K0A-2E0         F: +1(613)489-0995
PGP Privacy: http://www.cyberus.ca/~holman/gkholman.pgp
Training:  http://www.CraneSoftwrights.com/schedule.htm

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


Current Thread