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

Re: [xsl] Selecting/matching based on inherited attributes


Subject: Re: [xsl] Selecting/matching based on inherited attributes
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 19 Apr 2002 10:33:32 +0100

Wendell wrote:
> "all myelem elements for which
>      a first ancestor-or-self with an @att1 has @att1='d'
>      and
>      a first ancestor-or-self with an @att2 has @att2='c'"
>
> which is what you say you want.
>
> OTOH, this doesn't really help, does it? The whole tree will still
> be walked collecting myelem elements, to be filtered with the
> predicate. (I don't think there's a way to avoid walking the whole
> tree one way or another to get those myelems, since the whole idea
> is not to miss any.)

The other approach would be to work down from the top of the tree,
keeping track of the values of @att1 and @att2 as you go. Something
like:

<xsl:template match="*">
  <xsl:param name="att1" select="/.." />
  <xsl:param name="att2" select="/.." />
  <xsl:apply-templates>
    <xsl:with-param name="att1" select="($att1 | @att1)[last()]" />
    <xsl:with-param name="att2" select="($att2 | @att2)[last()]" />
  </xsl:apply-templates>
</xsl:template>

until you finally get to the 'myelem' elements and can test the
values:

<xsl:template match="myelem">
  <xsl:param name="att1" select="/.." />
  <xsl:param name="att2" select="/.." />
  <xsl:if test="$att1 = 'd' and $att2 = 'c'">
    ...
  </xsl:if>
</xsl:template>

Cheers,

Jeni

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


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



Current Thread