[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Using XPath to retrieve nodes by attribute.

Subject: RE: Using XPath to retrieve nodes by attribute.
From: "Kenny Akridge" <kenny@xxxxxxxxxxxxxxxxx>
Date: Thu, 29 Apr 2004 09:19:34 -0400
xpath retrieve attribute value
This will give you quickbrownfox.
Let me know if I have misunderstood your question.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/xml">
	<xsl:value-of select="CCC/DDD[@attrib='123'][1]"/>
	<xsl:value-of select="CCC/DDD[@attrib='456'][1]"/>
	<xsl:value-of select="CCC/DDD[@attrib='456'][2]"/>
</xsl:template>
</xsl:stylesheet>

-----Original Message-----
From: Manuel Reyes [mailto:Manuel.Reyes@xxxxxxxxx] 
Sent: Thursday, April 29, 2004 9:11 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Using XPath to retrieve nodes by attribute.

Hello all,

I have the following XML document:

<xml>
	<AAA>foo</AAA>
	<BBB>bar</BBB>
	<CCC>
		<DDD attrib="123">quick</DDD>
		<DDD attrib="456">brown</DDD>
		<DDD attrib="789">fox</DDD>
		<DDD attrib="123">jumped</DDD>
		<DDD attrib="456">lazy</DDD>
		<DDD attrib="789">dog</DDD>
	</CCC>
</xml>

If I run the following XPath query it returns the count of all nodes in
CCC that have an attrib value of "123":

xml/CCC/DDD[@attrib='123'] = 2

What I am trying to do now is retrieve a particular node based on the
position in the CCC node and its attribute, something like this:

xml/CCC/DDD[@attrib='123'][1] = quick
xml/CCC/DDD[@attrib='456'][1] = brown
xml/CCC/DDD[@attrib='456'][2] = lazy

This is based on information I found here:
http://www.w3schools.com/xpath/xpath_location.asp

Unfortunately this does work, can anybody tell me where I am going wrong

Thanks
Manuel

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.