[xsl] preceding-sibling inside for-each appears to fail

Subject: [xsl] preceding-sibling inside for-each appears to fail
From: Ted Stresen-Reuter <tedmasterweb@xxxxxxx>
Date: Sun, 9 Feb 2003 16:05:57 -0600

I'm trying to get the value of an attribute in the preceding sibling inside a for-each loop. The code below successfully captures the following-sibling, but always returns the same output for the preceding-sibling. What am I doing wrong?

Sample XML:
   <attribute name="accents_db"
              programs="htfuzzy htsearch"
              category="File Layout" >
	The database file used for the fuzzy "accents" search
	algorithm. This database is created by
	<ref type="program">htfuzzy</ref> and used by
	<ref type="program">htsearch</ref>.

   <attribute name="accept_language"
              block="Server" >
     <example>en-us en it</example>
	This attribute allows you to restrict the set of natural languages
	that are preferred as a response to an HTTP request performed by the
	digger. This can be done by putting one or more language tags
	(as defined by RFC 1766) in the preferred order, separated by spaces.
	By doing this, when the server performs a content negotiation based
	on the 'accept-language' given by the HTTP user agent, a different
	content can be shown depending on the value of this attribute. If
	set to an empty list, no language will be sent and the server default
	will be returned.

   <attribute name="add_anchors_to_excerpt"
              category="Presentation:How" >
	If set to true, the first occurrence of each matched
	word in the excerpt will be linked to the closest
	anchor in the document. This only has effect if the
	<strong>EXCERPT</strong> variable is used in the output
	template and the excerpt is actually going to be displayed.

Sample XSL:
<xsl:template name="alphabet">
<xsl:for-each select="//HtdigAttributes/attribute">
<p>checking: <xsl:value-of select="@name" /></p>
<p>preceding sibling = <xsl:value-of select="preceding-sibling::attribute/@name" /></p>
<p>following sibling = <xsl:value-of select="following-sibling::attribute/@name" /></p>

Sample Output:
<p>checking: accents_db</p>
<p>preceding sibling = </p>
<p>following sibling = accept_language</p>
<p>checking: accept_language</p>
<p>preceding sibling = accents_db</p>
<p>following sibling = add_anchors_to_excerpt</p>
<p>checking: add_anchors_to_excerpt</p>
<p>preceding sibling = accents_db</p>
<p>following sibling = allow_double_slash</p>
<p>checking: allow_double_slash</p>
<p>preceding sibling = accents_db</p>
<p>following sibling = allow_in_form</p>

As you can see, following-sibling successfully returns the following sibling, but preceding-sibling always returns the first node rather than the preceding-sibling node. I've tried changing the way I'm referencing the node values to no avail. I would greatly appreciate any pointers in what I'm doing wrong here.


Ted Stresen-Reuter

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

Current Thread