This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Selecting/matching based on inherited attributes


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]