Re: [xsl] node() problem

Subject: Re: [xsl] node() problem
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 04 Jul 2003 13:27:30 -0400
Steve,

The "empty" node is in your source. It's undoubtedly a whitespace-only text node, which you may be deleting in your post to us, since you only see a line feed or something as apparently innocuous.

Notice your template matches text nodes by virtue of matching "node()". If you don't want text nodes to be processed by the template, don't match them, or if you do but want to skip whitespace-only text nodes, find another way to remove them such as xsl:strip-space.

Actually, XMLSpy is the one with the bug here: MSXML, which XMLSpy uses, strips these nodes by default before the XSLT engine sees the document, contrary to indications in the XSLT spec that suggest this job should be done by the XSLT processor. (By a strict reading of what constitutes legal input to the process they aren't *quite* non-conformant in this, but you can think of it as a bug anyhow. :-)

The other engines are doing the right thing.

match="@*|*" will fix the problem.

Cheers,
Wendell

At 12:00 PM 7/4/2003, you wrote:
Hi all,

A quick question:

I am using this piece of code:

<xsl:template match="@*|node()">
        <xsl:element name="_r">
        <xsl:attribute name="n">
                <xsl:value-of select="name(.)"/>
        </xsl:attribute>
        <ind><xsl:value-of select="."/></ind>
        </xsl:element>
</xsl:template>

To handle all of the tags not explicitly matched.

I would expect that:
<foo>goo</foo>

would be transformed to

<_r n="foo"><ind>goo</ind></_r>

However the output is:
<_r n="foo"><ind>goo</ind></_r>
<_r n=""><ind></ind></_r>

When run through msxml, xltproc, and through Java's xslt engine.
The only engine that produces the correct output is XMLSPY's transformation
engine, but it is simply too slow and not practical to run on large files.

Why is it that there appears to be an "empty" node that get's matched in the
first 3 engines?
Is this correct and do you know a fix for it?

___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_ "Thus I make my own use of the telegraph, without consulting the directors, like the sparrows, which I perceive use it extensively for a perch." -- Thoreau


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



Current Thread