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


Hi Michael!

At 05:45 PM 4/18/2002, you wrote:
>I know how to check the ancestor value from within the element's content:
>
>eg: <xsl:if test="ancestor-or-self::*[@att1][1]/[@att1='d'] and
>ancestor-or-self::*[@att2][1]/[@att2='c']">

Well ... except to point out what you already know, that you have a few 
specious '/' characters in this XPath ...

>But that would mean walking through the entire nodeset each time I wanted
>to create output.
>
>Is there a way to check from outside the element?
>
>eg (knowing this is illegal, but trying to show intent):
>
><xsl:apply-templates select="//myelem/[ancestor-or-self::*[@att1][1]/[@att1
>='d']][ancestor-or-self::*[@att2][1]/[@att2='c']]"/>
>
>in plain english: apply templates to all "myelem" nodes that have a
>closest-att1 of "d" and a closest-att2 of "c".

Yes, this should work, and the test should be just the same as when 
matching each element instead of selecting from the top. I.e. (correcting 
for the slashes and tweaking a bit for readability, but the same effect):

<xsl:apply-templates select=

"//myelem[ancestor-or-self::*[@att1][1][@att1='d']
        and
        ancestor-or-self::*[@att2][1][@att2='c']]"/>

translates as

"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.)

If feasible, a two-pass approach has its attractions. XPath is not really 
designed to make this having-a-value-by-inheritance thing very transparent 
(the exception of the obscure lang() function proving this rule).

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
   Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


 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]