Re: position()

Subject: Re: position()
From: Mike Brown <mike@xxxxxxxx>
Date: Sun, 16 Apr 2000 10:29:01 -0600 (MDT)
Dan Morrison wrote:
> For-each works on an ordered set, but templates get applied willy-nilly.

There's no rule that templates get applied willy-nilly. In fact, David
Carlisle and I were just discussing how the XSLT spec says in so many
words that for both xsl:for-each and xsl:apply-templates, "the nodes are 
processed in document order" in the absence of an xsl:sort specifying
some other order.

In order (ha) for any template other than the one that matches the root
node to be applied, there must be an instruction somewhere, either in an
explicit or a built-in template, that says <xsl:apply-templates
select="foo">, where foo is an XPath expression identifying a node-set to
be processed.

If Dave Pawson traces the order of execution of templates, starting at the
root node, and taking into account the built-in templates, he will
probably find that he accidentally told the XSL processor to process the
'section' elements as part of a list of nodes in which those element nodes
occupy the 2nd, 6th, 10th, etc positions in the list.

> Your results in the second case give a glimpse into what the parser was
> doing in between the last two 'sections'.

Right.

> It's all about context. You're asking for a postion in an unsorted,
> non-homogenous list.

The list will have some kind of order, either document order or the order
imposed with an xsl:sort, but we don't know what the list is without
seeing the rest of his stylesheet.

> This is such an odd quirk It ought to be put in a FAQ somewhere. 

Dave Pawson is the maintainer of the FAQ :)

> seems legal to me, but a very odd side-effect.

Don't use side-effect to describe undesirable/confusing results :)

-Mike


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


Current Thread