xsl-list
[Top] [All Lists]

Re: characters in xsl

2004-11-11 12:09:21
Hi Geertz,

Okay, more tweaking of fine points.

I hope we're training a new generation of XSLT syntax hawks here ... 'twould be nice. :->

At 12:39 PM 11/11/2004, you wrote:
'//stone' is a 'better match' in the sense that it is more specific.

Actually "specificity" has to do with this only incidentally. It's a better match because it's defined by the rules (which happen to be based on a rough notion of "specificity") as a better match:

named node tests (on the child or attribute axis) get priority 0
  e.g. "child::stone", "attribute::feather"
simple node tests (wildcards such as *) get priority -0.5
  e.g. "*", "text()"
anything else gets priority 0.5

The rules for this are at http://www.w3.org/TR/xslt#conflict, XSLT 5.5 "Conflict Resolution for Template Rules"

 It will not match the root element if its name would be stone.

Nope. What is called the "root element" in other XML contexts is better called the "document element" in XSLT because it is, itself, the child of the "root node" of the tree. The root node, referred to in XPath as "/", is not an element, nor is it the child of anything; nor does it have a name. But all elements are the child of something (either of another element or of the root). So match="stone" will match the document element if it's named 'root'. (Try it. :-)

Thus not all 'stone' elements in the document, but all _child_ elements (= elements that have a parent) named 'stone'. It works in fact the same as './/stone', where the current element will not be included if it happened to be a 'stone' element as well.

As I explained earlier (and I think David did too) the current element has no bearing on whether a match pattern matches any particular node.

To match or select the root element if it is stone, use '/stone'. To match any element stone, just use 'stone'.

Correct, and correct.

To access any stone element in the document, even the root, (at any moment during the transformation), use '/descendant-or-self::stone'.

But "//stone" (short for /descendant-or-self::node()/child::stone) or /descendant::stone will also get all the stone elements in the document, because of that root node (since all element nodes are children of something).

In short: it usually doesn't make sense to use // in match patterns. And keep in mind that //stone in select patterns don't include the root element.

You mean "select expressions": there are no "select patterns" since the value of a 'select' attribute is never evaluated as a pattern. Only 'match', 'count' (on xsl:number) and 'from' (also on xsl:number) are evaluated as patterns.

Also, "//stone" will select a 'stone' document element, because traversing from the root it's found along the path "/descendant-or-self::node()/child::stone".

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--