Re: figuring out if one tag was directly preceding by another

Subject: Re: figuring out if one tag was directly preceding by another
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 11 Oct 2000 15:07:16 -0600 (MDT)
Eric Taylor wrote:
> Simplified, part of my XML looks like this:
> 
>    <para>here is some content<button.../> more optional content <link...
> /></para>
> 
> My problem is that if there is nothing between button and link (i.e.,
> <button.../><link... />) then I need to do something marginally different
> than if there is intervening content.  Is there any way to identify when
> processing the link template whether it was directly preceded by button.
> Thanks  Eric

'something' intervening = a text node is the 'link' element's preceding
sibling. 'nothing' intervening = an element node ('button') is the link
element's preceding sibling.

so if you have a template that matches "link" elements, you could probably
do something like

<xsl:if test="generate-id(preceding-sibling::node()[1]) =
generate-id(preceding-sibling::*[1])"/>
  ...
</xsl:if>

to test for the first preceding sibling node and the first preceding
element having the same internal ID (and thus being the same node). The
predicate [1] on each is probably not necessary since generate-id() will
only look at the first node in the given set, but I've included it for
clarity.

Untested code.

   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at         My XML/XSL resources:
webb.net in Denver, Colorado, USA           http://www.skew.org/xml/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread