Re: [xsl] position() question

Subject: Re: [xsl] position() question
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Fri, 26 Sep 2008 12:18:48 +0100
> I just came across an example where I am wondering about the value that is
> calculated by position().
>
> Please have a look at:
> http://msdn.microsoft.com/de-de/library/ms256214.aspx
>
> In my enviromnent (saxon 8) I dont get the desired result as in the example.
> My value of position() is 2,4,6,...,22 instead of 1,2,3,...,11. So every
> item gets the color yellow. But I dont know why, because the iteration goes
> over the 11 "item" elements. Where do the other elements come from that are
> counted?


In between each <item> element is a whitespace only text node which
gets included in the list of nodes to process by the apply-templates
call, so it goes:

[whitespace] 1
<item> 2
[whitespace] 3
<item> 4

etc

The Microsoft XML parser strips those whitespace only nodes by default
(incorrectly assuming they are just presentational markup from the
indentation of the XML) so the list of nodes to process becomes:

<item> 1
<item> 2
<item> 3

The "solution" to the problem is either:

a) tell the Microsoft parser not strip the whitespace only text nodes

or

b) be more explicit in the apply-templates call to only process
elements eg <xsl:apply-templates select="*"/>


-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread