searching for closest previous element

Subject: searching for closest previous element
From: stephenng@xxxxxxxxxxxx
Date: Wed, 18 Mar 1998 11:57:46 +0000
Here's the side-effect thread all over again.

When handling element "X", I would like to find the closest previous
occurrence of element "Y" in the document, because I need to look up
some attribute of element "Y".  For perverse reasons, elements "X"
and "Y" can occur anywhere in the document, at any level, so the
occurrence of "Y" that I need to look up would be the closest
previous element if you flattened the whole tree.

I have a routine to do this, but it's really really slow.

In a language with side-effects, every time I ran across "Y" I would 
set a global "LastY", which I could reference when I process "X".

In DSSSL, however, I have to rummage through the tree over and over 
again every time I hit an "X".  I've structured my tree-search so 
that it (recursively) searches the last node first by calling 
"reverse" on the node list.  

"Reverse" takes a lot of time with many elements.  But there seems no 
way around it: there's no quick way to access the last node in a node 
list, so that I can walk the tree list backwards.

Is the short answer that I shouldn't have a document structured like 
this?  If the "Y" I was interested in was an ancestor of "X", then I 
wouldn't have these problems.  Perhaps I should write a Jade program 
to create a new document that has this property?

Is this similar to the footnote numbering problem?  

TIA,

Steve


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


Current Thread
  • searching for closest previous element
    • stephenng - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id MAA29235Wed, 18 Mar 1998 12:00:36 -0500 (EST) <=
      • Norman Walsh - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id MAA00392Wed, 18 Mar 1998 12:40:40 -0500 (EST)
      • Paul Prescod - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id KAA20931Thu, 19 Mar 1998 10:32:32 -0500 (EST)
      • <Possible follow-ups>
      • stephenng - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id NAA01051Wed, 18 Mar 1998 13:28:07 -0500 (EST)
        • stephenng - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id OAA17663Thu, 26 Mar 1998 14:25:03 -0500 (EST)