[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Indexing Tree Elements

Subject: Re: Indexing Tree Elements
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 07 Jul 2000 09:16:55 -0400
foo.xsl
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@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-04-7 Next instructor-led training: 2000-09-19/20,2000-10-03,2000-10-04, - 2000-10-05,2000-11-13,2001-01-27


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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.