[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Semantics of "match"

Subject: [xsl] Semantics of "match"
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxx>
Date: Mon, 3 Feb 2014 09:58:41 -0500


On Sun, Feb 2, 2014 at 10:54 PM, Graydon <graydon@xxxxxxxxx> wrote:
> 3.0 allows more axis references in template matches than 2.0 did; 2.0 is
> child and attribute only, 3.0 allows descendant.  (I think it allows all
> ForwardAxis axises.)
> So
> <xsl:template match="descendant::*"/>
> is a legal match attribute value.
> Leaving any use of except or intersect or union out of it for now just
> what does that match mean?

Well, the old (1.0) meaning could reduce as follows.

Consider match as a function returning a Boolean, true() if it
matches, false() if it doesn't.

As an argument to the function, along with the pattern itself, we
accept a node. Either the node matches the pattern, or it doesn't.


The function returns true() if (and only if) in the tree containing
the node, there exists a node from which, using the pattern as an
XPath expression, the node in question will be returned.

(If your head now hurts, this is because matching may be easier to
understand intuitively than it is to explain. :-)


some $n in (root($node)//(child::node() | @*)) satisfies
   ($node intersect $n/eval($pattern))

where $n/eval($pattern) evaluates pattern $pattern as an XPath
expression from context $n.

If this holds for 3.0 (and mind you it doesn't, quite), then
match="following-sibling::li" would match every 'li' in your document
except first children of their respective parents.

(Hey look, 'except' works fine as an English preposition.)

As always, I trust those who know better will correct me.

Also -- in passing -- I wonder if this will be a potential source of
bugs if a pattern like 'following-sibling::li" matches due to the
presence of a comment or processing instruction.

Cheers, Wendell

>  I'm not having any luck with 5.6.3 (The
> Meaning of a Pattern) in the spec, which covers child and namespace and
> attribute axises, with what looks to me like a special case for
> document-nodes, but it doesn't seem to cover descendant or the following
> axises, and I'm having some trouble figuring out what nodes such a
> template would be expected to match.

Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables

Current Thread