<RefEntry id="component-child-number">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename component-child-number.html>

<RefMeta>
  <RefEntryTitle>component-child-number</RefEntryTitle>
  <RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>

<RefNameDiv>
  <RefName>component-child-number</RefName>
  <RefPurpose>Find child-number within a component</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(component-child-number inputnd complist)
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
Finds the first ancestor of <literal>inputnd</literal> in <literal>complist</literal> and then counts 
all the elements of type <literal>inputnd</literal> from that point on and returns
the number of <literal>inputnd</literal>.  (This is like a <literal>recursive-child-number</literal>
starting at the first parent of <literal>inputnd</literal> in <literal>complist</literal>.)</para>


</RefSect1>

<RefSect1><Title>Author</Title>

<para>
Norman Walsh, &lt;ndw@nwalsh.com&gt;
</para>
</RefSect1>
<RefSect1><Title>Source Code</Title>

<ProgramListing>
(define (component-child-number inputnd complist)
  ;; Find child-number within a component
  (let loop ((nl (component-descendant-node-list inputnd complist))
	     (num 1))
    (if (node-list-empty? nl)
	0
	(if (node-list=? (node-list-first nl) inputnd)
	    num
	    (if (string=? (gi (node-list-first nl)) (gi inputnd))
		(loop (node-list-rest nl) (+ num 1))
		(loop (node-list-rest nl) num))))))
</ProgramListing>
</RefSect1>

</RefEntry>
