Meaning of XPath spec?

Subject: Meaning of XPath spec?
From: chet@xxxxxxxxxxxxxx
Date: Tue, 17 Aug 1999 16:20:16 -0400
In reading thru the XPath spec, I found the following in section 3.3.

     NOTE: The meaning of a Predicate depends crucially on which axis
     applies. For example, preceding::foo[1] returns the first foo
     element in reverse document order, because the axis that applies
     to the [1] predicate is the preceding axis; by contrast,
     (preceding::foo)[1] returns the first foo element in document
     order, because the axis that applies to the [1] predicate is the
     child axis.

I searched thru the grammar, and could not find a way to parse the
second expression.  Nevertheless, XML4J returns the right thing.

In attempting to decipher this path, I wrote the following XML file

================================================================
<?xml version="1.0"?>
<doc>
<buzz>first buzz</buzz>
<foo>first foo</foo>
<foo>second foo</foo>
<foo>third foo</foo>
<bar/>
</doc>
================================================================

and the following XSL file

================================================================
<?xml version="1.0"?> 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";>

  <!-- Root xsl:template - start processing here -->
  <xsl:template match="/">
		    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="doc">
	  Rule1(<xsl:apply-templates select="bar"/>)
  </xsl:template>

  <xsl:template match="bar">
    Rule2[preceding::foo](<xsl:copy-of select="preceding::foo"/>)
    Rule2[preceding::foo[1]](<xsl:copy-of select="preceding::foo[1]"/>)
    Rule2[(preceding::foo)](<xsl:copy-of select="(preceding::foo)"/>)
    Rule2[(preceding::foo)[1]](<xsl:copy-of select="(preceding::foo)[1]"/>)
  </xsl:template>

</xsl:stylesheet>
================================================================

and the output from the Lotus XSL processor was

================================================================
          Rule1(
(1)    Rule2[preceding::foo](<foo>first foo</foo><foo>second foo</foo><foo>third foo</foo>)
(2)    Rule2[preceding::foo[1]](<foo>third foo</foo>)
(3)    Rule2[(preceding::foo)](<foo>first foo</foo><foo>second foo</foo><foo>third foo</foo>)
(4)    Rule2[(preceding::foo)[1]](<foo>first foo</foo>)
  )
================================================================

There are quite a few things I don't understand:

(a) why do (1) and (3) produce the same thing, and yet, (2) and (4)
produce different things?

(b) what does

  (preceding::foo)[1]

even mean?  For that matter,

  (preceding::foo)

(c) what is its unabbreviated syntax?

Thanks,
--chet--


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


Current Thread