This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: position()


Dave Pawson wrote:
> 
> I'm using position() function in two places.
> 
> Once in the root template in a for-each loop.
> Once in a template
> 
> The 'number' I'm getting back is different in each case.
> In the former case I get 1 to 7,
> in the latter case I get 2 6 10 14 18 22 26
> 

That's fascinating.

Yes, I can see how that would happen :-) It's funny.

For-each works on an ordered set, but templates get applied willy-nilly.
Generally in some sort of tree traversal, but how that happens is not
restricted. A parser applying-templates is likely to encounter many
nodes in the source document and deal with them as they occur. 

This means that if any position count at all is kept, it may hold the
count of _total_templates_applied_so_far_ and not
_nodes_of_a_certain_type_processed_ 
Your results in the second case give a glimpse into what the parser was
doing in between the last two 'sections'.

Unfortunately, I can't see a useful way of using position() in this way.
I'm sort of surprised you'd get any result at all. 
It's all about context. You're asking for a postion in an unsorted,
non-homogenous list.

I'd guess you have to rework your structure to only use for-each. Try
making more advanced select queries (such as within the apply-templates
call that starts this off) and look at call-template to get things done.

This is such an odd quirk It ought to be put in a FAQ somewhere. It
seems legal to me, but a very odd side-effect. Which Parser was it?

Note, This is just my analysis of a possible cause. The truth may be
even stranger.

.dan.

:=====================:====================:
: Dan Morrison        : The Web Limited    :
:  http://here.is/dan :  http://web.co.nz  :
:  dman@es.co.nz      :  danm@web.co.nz    :
:  04 384 1472        :  04 495 8250       :
:  025 207 1140       :                    :
:.....................:....................:
: If ignorance is bliss, why aren't more people happy?
:.........................................:


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]