[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Selecting/matching based on inherited attributes

Subject: Re: Selecting/matching based on inherited attributes
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 19 Apr 2002 10:33:32 +0100
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.