File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes get element based on attribute value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "get element based on attribute value" Watch "get element based on attribute value" New topic
Author

get element based on attribute value

rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
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

Joined: Jul 13, 2001
Posts: 3150
Try this
<xsl:value-of select="myElement[@myAttribute='attValue']/childElement" />


Spritle Software Blogs
rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
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

Joined: Mar 22, 2002
Posts: 208
It actually works using //*, sorry.
[ June 09, 2004: Message edited by: rick collette ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get element based on attribute value