This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Selecting/matching based on inherited attributes
- From: mpriestl at ca dot ibm dot com
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 18 Apr 2002 17:45:49 -0400
- Subject: [xsl] Selecting/matching based on inherited attributes
- Reply-to: xsl-list at lists dot mulberrytech dot com
Okay, I've done my homework (consulted the FAQ and searched the archives)
and I'm still stuck.
Here's what I'm trying to do:
Given
<myelems att1="a" att2="b">
<myelem id="1"/>
<myelems att2="c">
<myelem id="2" att1="d"/>
<myelem id="3" att1="d" att2="e"/>
</myelems>
<myelem id="4" att1="d" att2="c">
</myelems>
I want output sorted/selected by att1 and att2, with values inherited from
the closest ancestor.
All with att1=a (ignoring att2)
<output id="1"/>
<output id="4"/>
All with att2=c, except for att1=a:
<output id="4"/>
All with att1=d and att2=c:
<output id="2"/>
<output id="4"/>
And so on...
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']">
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".
So far the only thing I can think of is to run two transforms, the first to
make all the attribute values explicit, the second to do a simple literal
sort. But that seems really awkward - I know there are lots of inherited
attributes about, and I'm hoping someone else has already come up with a
solution to this.
Many thanks for any help,
Michael Priestley
mpriestl@ca.ibm.com
Dept 833 IBM Canada t/l: 969-3233 phone: 905-413-3233
Toronto Information Development
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list