[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
Hi,

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:
<HtdigAttributes>
   <attribute name="accents_db"
              type="string"
              programs="htfuzzy htsearch"
              version="all"
              category="File Layout" >
     <default>${database_base}.accents.db</default>
     <example>${database_base}.uml.db</example>
     <description>
	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>.
     </description>
   </attribute>

   <attribute name="accept_language"
              type="string_list"
              programs="htdig"
              version="3.2.0b4"
              category="Indexing:Out"
              block="Server" >
     <default></default>
     <example>en-us en it</example>
     <description>
	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.
     </description>
   </attribute>

   <attribute name="add_anchors_to_excerpt"
              type="boolean"
              programs="htsearch"
              version="3.1.0"
              category="Presentation:How" >
     <default>true</default>
     <example>no</example>
     <description>
	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.
     </description>
   </attribute>
</HtdigAttributes>

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>
</xsl:for-each>
</xsl:template>


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>

Discussion
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.


Sincerely,

Ted Stresen-Reuter


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



Current Thread