RE: [xsl] Find the root element from an attribute node

Subject: RE: [xsl] Find the root element from an attribute node
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 10 Jul 2008 14:59:34 +0100
> I want to detect 
> whether the ancestor of the particular href is <html> as 
> opposed to <map>, <task>, <concept> or <reference> so that I 
> can treat it differently. How do I do it?
> 
> <xsl:template match="@href[ancestor::html]">

> 
> Is never going to work. 

Why not? match="html//@href" is more conventional, but your form is just as
good. It assumes, of course, that you somewhere do apply-templates to the
attribute node.

> I've read with bewilderment the 
> threads about the xslt spec and that attributes are children 
> of elements but elements are not parents of children... 

No you've got that the wrong way around.

The relationship between elements and subelements is called "child" in one
direction and "parent" in the other.

The relationship between elements and attributes is called "attribute" in
one direction and "parent" in the other.

You can always go up from an attribute using the parent or ancestor axes.

Michael Kay
http://www.saxonica.com/

Current Thread