Re: Counting Nodes

Subject: Re: Counting Nodes
From: Brandon Ibach <bibach@xxxxxxxxxxxxxx>
Date: Thu, 24 Feb 2000 15:22:32 -0600
Quoting Maltby, David G <david.g.maltby@xxxxxxxx>:
> I am working on producing RTF from content marked up with DTD which I do not
> control.  It contains chunks such as:
> <alert>
> <text type="list:num">
>   <text>List Item 1</text>
>   <text type="list:alpha">
>     <text>List Item a</text>
>     <text>List Item b</text>
>   </text>
>   <text>List Item 2</text>
>   <text>List Item 3</text>
> </alert>
> [...]
> Counting-wise this works great, the problem is when looking at the text
> nodes containing "List Item 1", "List Item 2", or "List Item 3",
> text-siblings starts out containing 13 nodes.  The procedure exits,
> respectively, on the 1st, 8th, and 12th node.  My RTF looks like:
>   1. List Item 1
>     a. List Item a
>     b. List Item b
>   8. List Item 2
>   12. List Item 3
> For non-built-in procedures, I have used the procedure definitions found in
> the DSSSL Documentation Library.  I can not for the life of me figure out
> what group of 13 nodes (siblings) is returning to me.  Any ideas on how I
> might debug this?  Is there a more elegant method I have not considered?
   Okay, I have to theorize here, a bit, because I don't have the DTD
you're using (in addition to the fact that I don't really know the
SGML whitespace handling rules very well).  The 13 nodes are: The
<text> containing "List Item 1", the newline and two spaces following,
the <text> containing the sublist, the two spaces at the beginning of
the line following the closing tag of that, the <text> containing
"List Item 2", the newline and two spaces following, the <text>
containing "List Item 3", and the following newline.  That should be a
total of 13, and should match the numbering you're getting.
   So, the solution is to just include a clause in your (cond) to
check the class of each node and ignore it completely (including *not*
incrementing the counter) if it isn't an element.  And while you're
modifying that procedure, you'll want to drop the parens around "cnt"
in the clause with (node-list-empty?).  This clause should,
theoretically, never fire, but if it did, it would try to execute cnt,
which is not a procedure.
   And, for the record, the problem (or "confusion", perhaps) here is
that, I expect, the "text" element is declared to have mixed content
in order to allow either the text of item or a list of other <text>s,
thus the mixture of elements and data-chars in the node-list you're
getting from (siblings).
   I believe I have a procedure around here somewhere that works like
(debug) for node-lists, dumping out quite a bit of information about
their members but returning the node-list unscathed.  Let me know if
you're interested, and I'll dig it up and make sure it's in working
order. :)

-Brandon :)

 DSSSList info and archive:

Current Thread