Re: [xsl] thoroughly confused about node() matching

Subject: Re: [xsl] thoroughly confused about node() matching
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 03 Mar 2003 12:21:26 -0500
Robert,

The following is As I Understand It. The authority on this should be the Recommendations(XSLT and XPath), on the w3.org site.

At 11:08 AM 3/3/2003, you wrote:
i get two different outputs using xsltproc and saxon.

Hm.


  xsltproc does *not* generate output for comments or
processing instructions, while saxon *does*.

  i have read a number of docs, including tidwell's "XSLT",
kay's "XSLT Programmer's Reference", and the online docs
at www.w3.org, and i can say with assurance that every one
of those sources disagrees with the others when it comes to
defining what does and does not match "node()" in the context
of a template match.  (e.g., kay, p. 440 states that node()
will *not* match attribute nodes, while tidwell, p. 51, says
it will.  argh.)

This confusion arises because there's more than the node test "node()" involved here.


This template will match an attribute node:

<xsl:template match="attribute::node()"/>

or equivalently

<xsl:template match="@node()"/>

but this one will not:

<xsl:template match="node()"/>

because it's short for

<xsl:template match="child::node()"/>

and no attribute sits on the child:: axis (by definition).

  rather than get into the gory details of what each of these
sources says, it seems obvious to this here newbie that
*at least* one of xsltproc or saxon is generating incorrect
output.

I believe Saxon's behavior is correct in your instance, but keep in mind that nodes must be selected before they can be matched.


  can anyone point me at the definitive explanation as to
what nodes the "node()" match really matches?

The XPath Rec in section 2.3 is quite explicit when it says "A node test node() is true for any node of any type whatsoever". However a match pattern "child::node()" will test true only for nodes that are on a child axis (which excludes attribute nodes and the root node).


  specifically,
should the rules in my stylesheet match comment()s or
processing-instruction()s, to override the built-in
behavior which is to ignore them?

The subtlety is that the built-in behavior:


<xsl:template match="*">
  <xsl:template select="child::node()"/>
</xsl:template>

does select PIs and comments, only their built-in rule:

<xsl:template match="comment() | processing-instruction()"/>

suppresses them.

So it's a bit complex. Another wrinkle is that it's possible there's something different happening in the different processors' parsers. We'll be hearing more.... :->

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


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



Current Thread