Re: Axis problem

Subject: Re: Axis problem
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 12 Sep 2000 19:09:14 +0100
Juergen,

>Instead of the XXXXX I tried several XPath-Expressions (parent,
>ancestor, ...), but I never get the @name of the component which
>properties I am processing now. The other stuff (propertyName and
>specialPropertyName) works correctly.

It sounds like you're on the right track.  The XPath has to take you from
the current node to the 'component' element, and then get the value of its
'name' attribute.  The current node, within the xsl:for-each in your
template, is a 'property' element, so the relevant piece of the hierarchy
looks like:

<component name="...">
           ^^^^^^^^^^  you want to get here
  <properties>
    <property />   <-- you are here
  </properties>
</component>

You could class the 'component' element that contains the current node as
the most recent 'component' ancestor of the current node:

  ancestor::component[1]

or as the parent 'properties's parent 'component' (which is slightly better
because it means even an unoptimised XSLT processor won't collect together
a list of all the ancestors):

  parent::properties/parent::component

or shorter (as the names of the parents aren't in question):

  parent::*/parent::*

or finally in shorthand as the parent element's parent:

  ../..

Once you've got to the 'component' element, getting to the 'name' attribute
involves the attribute axis, either as:

  attribute::name

or, in shorthand,

  @name

So you're looking for either:

<xsl:value-of select="parent::properties/parent::component/attribute::name" />

Or, shorter:

<xsl:value-of select="parent::*/parent::*/attribute::name" />

Or, shortest:

<xsl:value-of select="../../@name" />

Or any combination of the above :)

I hope that this helps,

Jeni

Jeni Tennison
http://www.jenitennison.com/


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


Current Thread