This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get element based on attribute value

 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to locate an element based on its unique
attribute value. There are lots of elements in the
hierarchy, I only show relavant ones here.



If "attValue" is unique for all elements, and I want to
locate myElement and then get childElement value.

I did the following, but it does not work:

<xsl:value-of select="//*[myAttribute='attValue']/childElement"/>

Could any one see what I did wrong?

regards,
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this
<xsl:value-of select="myElement[@myAttribute='attValue']/childElement" />
 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Sorry, I did not make it clear: the element I need locate
is unknown, so I cannot put "myElement" there.

//*[@myAttribute='attValue'] should locate the element
with attribute value "attValue" from all elements of the
entire xml document, right?


Originally posted by Balaji Loganathan:
Try this
<xsl:value-of select="myElement[@myAttribute='attValue']/childElement" />
 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It actually works using //*, sorry.
[ June 09, 2004: Message edited by: rick collette ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic