This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: how to select nodes based on attribute values
- To: xsl-list at mulberrytech dot com
- Subject: RE: how to select nodes based on attribute values
- From: sara dot mitchell at ps dot ge dot com
- Date: Thu, 5 Oct 2000 19:49:41 -0400
- Reply-To: xsl-list at mulberrytech dot com
It depends to some extent on whether your
element_id is defined as type ID in the DTD and
pick_id is defined as type IDREF in the DTD.
If they are, this template should work:
<xsl:template match="b">
<!-- whatever you need to do first -->
<xsl:apply-templates select="id(@pick_id)"/>
<!-- whatever you need to do later -->
</xsl:template>
The id() function looks for the single element with
an attribute of type ID that has a value equal to
what's inside the parens -- thus it's looking for an element
with an attribute that matches the value of pick_id.
If you're DTD is not set up this way, you can do it
slightly differently.
<xsl:template match="b">
<xsl:variable name="matchto" select="@pick_id"/>
<xsl:apply-templates select="//*[@element_id=$matchto]"/>
</xsl:template>
This one uses '//*' to search the entire document tree for any
element (the name is not important) that has an element_id
attribute with a value matching pick_id. This method is not
so efficient :-) And someone else may come up with a better way
(using keys perhaps?). But this should work.
Sara
> -----Original Message-----
> From: Archie Russell [mailto:archier@doubletwist.com]
> Sent: Thursday, October 05, 2000 3:50 PM
> To: 'XSL-List@mulberrytech.com'
> Subject: how to select nodes based on attribute values
>
>
>
> is there a way to select a node based on attribute value
> matching attribute
> value in another node?
>
> example
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xxx>
> <a element_id="1" name="xxx"/>
> <a element_id="2" name="yyy"/>
> <b pick_id="1"/>
> </xxx>
>
> i want to select all 'a' elements that have element_id
> matching the value of
> 'b's pick_id (my context is being "in" b)
> i've tried [] but i can't see how to refer to the attributes
> of "a" and "b"
> simultaneously.
>
> thanks for any help,
> archie
>
> archie russell
> doubletwist.com
> 510-587-5766
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list