Re: Indexing Tree Elements

Subject: Re: Indexing Tree Elements
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Aug 2000 13:08:27 -0400
At 00/08/17 10:14 +0100, Lee Goddard wrote:
<xsl:if test="not(@foo = preceding-sibling::*[@foo][1]/@foo)">

to only reveal certain content if it is there is a difference
between attribute values found in the node immediately preceeding
the current node.

It seemed to work for a while, but now seems to show the value of
the first node's attribute.

Right ... because there are no preceding-siblings, the comparison of @foo would be false, so the negation would be true.


Would the following do what you wish?

    <xsl:if test="preceding-sibling::*[@foo] and
                  not(@foo = preceding-sibling::*[@foo][1]/@foo)">

Attached below is an example ... I hope this helps.

............. Ken

T:\ftemp>type goddard.xml
<?xml version="1.0"?>
<doc>
 <test foo="a" item="1"/>
 <test foo="b" item="2"/>
 <test foo="b" item="3"/>
 <test foo="c" item="4"/>
 <test foo="d" item="5"/>
 <test foo="d" item="6"/>
</doc>
T:\ftemp>type goddard1.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:template match="/">                         <!--root rule-->
  <xsl:for-each select="//test">
    <xsl:if test="not(@foo = preceding-sibling::*[@foo][1]/@foo)">
Found: <xsl:value-of select="@foo"/> in <xsl:value-of
                                                  select="@item"/>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>


T:\ftemp>xt goddard.xml goddard1.xsl <?xml version="1.0" encoding="utf-8"?>

Found: a in 1
Found: b in 2
Found: c in 4
Found: d in 5
T:\ftemp>type goddard2.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:template match="/">                         <!--root rule-->
  <xsl:for-each select="//test">
    <xsl:if test="preceding-sibling::*[@foo] and
                  not(@foo = preceding-sibling::*[@foo][1]/@foo)">
Found: <xsl:value-of select="@foo"/> in <xsl:value-of
                                                  select="@item"/>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>


T:\ftemp>xt goddard.xml goddard2.xsl <?xml version="1.0" encoding="utf-8"?>

Found: b in 2
Found: c in 4
Found: d in 5
T:\ftemp>rem


-- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) Web site: XSL/XML/DSSSL/SGML services, training, libraries, products. Book: Practical Transformation Using XSLT and XPath ISBN1-894049-05-5 Article: What is XSLT? http://www.xml.com/pub/2000/08/holman Next public instructor-led training: 2000-09-19/20,2000-10-03, - 2000-10-04,2000-10-05,2000-10-09/10,2000-10-19,2000-11-12, - 2000-12-03/04,2001-01-27


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



Current Thread