Re: [xsl] Simple Question concerning [last()]

Subject: Re: [xsl] Simple Question concerning [last()]
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sat, 8 Feb 2003 11:44:03 -0800 (PST)
<Stefan.Wachter@xxxxxx> wrote in message
> Hi all.
> My question is about a [last()] predicate in a simple step. Running 
> the following stylesheet on itself yields unexpected results using 
> Saxon and Xalan.
> I thought the XPath ".//x[last()] should return the last x-Element in
> document order. However, it returns the first one. Changing the 
> selection to ".//x[2] returns nothing at all! Yet, the XPath ".//x" 
> returns all x-Elements and the first x-Element has the position 1 and

> the second 2.
> Is this a bug in the mentioned XSLT processors or have I missed 
> something?

You missed something. According to the XPath spec:

"// is short for /descendant-or-self::node()/"

Therefore, the expression:


is equivalent to:


This returns all "x" descendent elements, which are the last child of
their parent.

In your case all "x" elements are the only (that means the last) child
of their parent. Therefore, all are returned.



is equivalent to:


and returns all "x" descendent elements, which are the second child of
their parent.

But there are not two "x" elements which are children of the same
Therefore, nothing will be returned.

What you probably wanted was:




Hope this helped.


Dimitre Novatchev. -- the home of FXSL

Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.

 XSL-List info and archive:

Current Thread