Re: [xsl] Axis order and variables

Subject: Re: [xsl] Axis order and variables
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 23 May 2003 09:47:24 -0400
At 2003-05-23 20:16 +0700, gutman@xxxxxxxxxxxxxxxx wrote:
Consider the following XML

  <x n="1">
    <x n="2">
      <test/>
    </x>
  </x>

and transform it via the following XSLT:

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

<xsl:output method="text" encoding="UTF-8"/>

    <xsl:template match="/">
      <xsl:for-each select="//test">
        <xsl:variable name="x" select="ancestor::x"/>
        <xsl:value-of select="$x[1]/@n"/>
      </xsl:for-each>
    </xsl:template>

</xsl:transform>

What is the expected result? Is it "1" or "2"?

In your example the answer is "1".


If you had written:

<xsl:value-of select="ancestor::x[1]/@n"

you would have received the answer of "2".

If this is all what we have then the result of the above test
should be "1", since the value of a variable is an object
rather than an expression and thus is an (unordered) node-set.

Actually, XSLT orders the unordered node-set in document order, which is why the first one is returned.


Therefore, its members, when forced to be ordered,
should be ordered in document order.

Precisely ... which XSLT 1.0 does.


Is it a definite answer?

Yes.


Does it depend on a realization?

It shouldn't ... it is well defined.


I have run into this question because the result of
MSXML 3.0 and Saxon differs from that of MSXML 4.0:
the former give "1", while the latter gives "2".
Who is right? Or they are both right?

If what you say is true, then MSXML 4.0 is not producing the result according to XSLT 1.0. I'm running IE6 which, I thought, was running MSXML 4.0 and yet I get the correct answer.


I hope this helps.

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

--
Upcoming hands-on courses: (registration still open!)
-      (XSLT/XPath and/or XSL-FO) North America: June 16-20, 2003

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 (F:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 0-13-140374-5                              Definitive XSL-FO
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X              Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners:    http://XMLGuild.info
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc


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



Current Thread