RE: [xsl] Built in templates and issues getting the XSLT processor to navigate an input document

Subject: RE: [xsl] Built in templates and issues getting the XSLT processor to navigate an input document
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 25 Sep 2007 11:45:39 -0400
At 06:25 AM 9/25/2007, Mike Kay wrote:
<xsl:template match="a/b">
  <xsl:message> b found </xsl:message>
    <xsl:apply-templates select="a/b/c"/>

Your b element does not have a child called a, so select="a/b/c" starting at
b will select nothing. You want select="c".

This is because "a/b/c" is a relative path expression, which starts at the context node, which here is the current node (the node matching the template, which would be each 'b' element as it is matched).


"a/b/c" could also be written "child::a/child::b/child::c" (the long syntax), which has the virtue of making very clear what is happening, while of course being more verbose.

In contrast to a relative path, an absolute path such as "/a/b/c" would not navigate from the current node, but from the root of the document. But of course this would retrieve all 'c' elements inside 'b' elements inside 'a' element children of the root (document node), not just 'c' elements inside the particular 'b' element you happen to be matching.

The notion of processing context, and (along with it) node selection using relative paths, is closely entangled with the processing model's notion of template matching, and a great part of what enables it to work so nicely.

Indeed, <xsl:apply-templates/> (in the built-in templates and elsewhere) is short for

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

... i.e., selecting all the child nodes of the node (element) matched, using a relative path.

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 ======================================================================

Current Thread