This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Indexing Tree Elements


Hi Folks,

I've been using a line suggested below by Ken Holman

<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.  I've got around this by using the
same code but replacing 'preceding' with 'following'.

But has anyone any idea what the problem might be?

Thanks in anticipation,
lee goddard
-- 
Lee Goddard  <l.goddard@sussex>
Research Centre for Cognitive Science, 
University of Sussex, Brighton UK


"G. Ken Holman" wrote:
> 
> At 00/07/07 13:14 +0100, David Carlisle wrote:
> > > is it possible that it may compare its attributes with the attributes
> > > of the previous document-tree node of the same level?
> >
> ><xsl:if test="@foo = preceding-sibling::*/@foo">
> >  'tis the same
> ></xsl:if>
> 
> I'm sorry if this sounds pedantic, but because the second argument is a
> node list, the above expression will be true if *any* of the preceding
> siblings nodes has an attribute named "foo" of the equal value.
> 
> To check the immediately preceding element for an attribute named "foo", I
> would think one would use:
> 
>    <xsl:if test="@foo = preceding-sibling::*[1]/@foo">
> 
> To check the the closest (in proximity) preceding element with an attribute
> named "foo", I would think one would use:
> 
>    <xsl:if test="@foo = preceding-sibling::*[@foo][1]/@foo">
> 
> I hope this helps and is considered constructive.
> 
> ................. Ken
> 
> T:\ftemp>type foo.xsl
> <?xml version="1.0"?><!--foo.xsl-->
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                  version="1.0">
> 
> <xsl:template match="/">                         <!--root rule-->
>    <xsl:for-each select="//test[last()]">
> @foo = preceding-sibling::*/@foo: <xsl:choose>
>      <xsl:when test="@foo = preceding-sibling::*/@foo">
>        <xsl:text>yes</xsl:text>
>      </xsl:when>
>      <xsl:otherwise>no</xsl:otherwise>
>    </xsl:choose>
> @foo = preceding-sibling::*[1]/@foo: <xsl:choose>
>      <xsl:when test="@foo = preceding-sibling::*[1]/@foo">
>        <xsl:text>yes</xsl:text>
>      </xsl:when>
>      <xsl:otherwise>no</xsl:otherwise>
>    </xsl:choose>
> @foo = preceding-sibling::*[@foo][1]/@foo: <xsl:choose>
>      <xsl:when test="@foo = preceding-sibling::*[@foo][1]/@foo">
>        <xsl:text>yes</xsl:text>
>      </xsl:when>
>      <xsl:otherwise>no</xsl:otherwise>
>    </xsl:choose>
>    <xsl:text> (</xsl:text>
>    <xsl:value-of select="preceding-sibling::*[@foo][1]/@foo"/>
>    <xsl:text>)</xsl:text>
>    </xsl:for-each>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> T:\ftemp>type foo.xml
> <?xml version="1.0"?>
> <doc>
>   <test foo="x">a</test>
>   <test foo="y">b</test>
>   <test        >c</test>
>   <test foo="z">d</test>
>   <test        >e</test>
>   <test foo="x">f</test>
> </doc>
> T:\ftemp>xt foo.xml foo.xsl
> <?xml version="1.0" encoding="utf-8"?>
> 
> @foo = preceding-sibling::*/@foo: yes
> @foo = preceding-sibling::*[1]/@foo: no
> @foo = preceding-sibling::*[@foo][1]/@foo: no (z)
> T:\ftemp>rem
> 
> --
> G. Ken Holman                    mailto:gkholman@CraneSoftwrights.com


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]