[xsl] Re: Re: weird behavior with last()

Subject: [xsl] Re: Re: weird behavior with last()
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 24 Jul 2001 12:25:27 -0700 (PDT)
Thomas B. Passin wrote:

> I got a different result after I copied your code by cut-and-paste.
> With Saxon, I always got the trailing "|", with msxml3 I never got it,
> whether or not I put the </MainMenu> onthe same line as </MainMenuItem> or
> not.
> Here, I am using Instant Saxon 6.2.2 running in XML Cooktop.
> Sounds like it's time for Mike Kay...

It's quite clear:

<xsl:apply-templates/>  is equivalent to:

<xsl:apply-templates select="node()"/>  

This ***includes*** whitespace-only nodes.

The difference in the behaviour of MSXML and Saxon is due to the fact that by
default the MSXML parser strips all whitespace-only nodes -- this makes the last
"SubMenuItem" also the last child node of its parent and then the condition in the
"xsl:if" is not true -- no " | " is added.

To see that this is really so, just change the top node of the xml source as I did:

<menus xml:space="preserve">
    <MainMenuItem URL="/">Home</MainMenuItem>
    <MainMenuItem URL="/strat.html">Strategic
    <MainMenuItem URL="/themes.html">Research

As can be seen, I added the xml:space="preserve" and then with my Xselerator the
result (as displayed by IE) was:

Home | Strategic Vision | Research Themes | Education | Commercial | Mission | Goals
| Philosophy | 

Asking the Xselerator to perform the transformation using Saxon, I again got the
same result.

Removing the xml:space="preserve" from the top element and specifying to the
Xselerator to use MSXML, the result is:

Home | Strategic Vision | Research Themes | Education | CommercialMission | Goals |

(the last " | " is missing)

This is very nice to see through the XSelerator Debugger, which steps through the
built-in template and clearly highlights the white-space only node, following the
last "SubMenuItem".

I usually do not use a Debugger, but this case shows the value of having a good XSLT
Debugger (in this case as part of the Xselerator) to make more understandable and to
literally visualise some more subtle aspects of XSLT processing.

Everybody, who had this tool, would be easily able to understand what is actually
happening in this situation.

Dimitre Novatchev.

Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger

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

Current Thread