Subject: [xsl] Axis order and variables From: gutman@xxxxxxxxxxxxxxxx Date: Fri, 23 May 2003 20:16:25 +0700 |
Hello, friends. 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"? I failed to find a definite answer in W3C specs. Here are some quotes: > XML Path Language (XPath) Version 1.0 > > 1 Introduction > > [...] An expression is evaluated to yield an object, > which has one of the following four basic types: node-set > (an unordered collection of nodes without duplicates) [...] > The value of a variable is an object, which can be > of any of the types that are possible for the value > of an expression [...] > > 2.4 Predicates > > [...] Thus, the ancestor, ancestor-or-self, preceding, > and preceding-sibling axes are reverse axes [...] > The proximity position of a member of a node-set > with respect to an axis is defined to be the position > of the node in the node-set ordered in document order > if the axis is a forward axis and ordered in reverse > document order if the axis is a reverse axis. [...] > For each node in the node-set to be filtered, > the PredicateExpr is evaluated [...] > with the proximity position of the node > in the node-set with respect to the axis > as the context position [...] > > XSL Transformations (XSLT) Version 1.0 > > 11.2 Values of Variables and Parameters > > [...] If the variable-binding element has a select > attribute, then the value of the attribute must be > an expression and the value of the variable is the object > that results from evaluating the expression. [...] 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. Therefore, its members, when forced to be ordered, should be ordered in document order. Is it a definite answer? Does it depend on a realization? 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? Thanks. -- Alexander E. Gutman XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Two errors reported using MSX, Kaine Varley | Thread | RE: [xsl] Axis order and variables, Michael Kay |
RE: [xsl] Maintaining character ent, Zarella Rendon | Date | RE: [xsl] xml to xsl: fo -> pdf for, Richard Kirby |
Month |