Re: [xsl] Using XPath to retrieve nodes by attribute.

Subject: Re: [xsl] Using XPath to retrieve nodes by attribute.
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Thu, 29 Apr 2004 06:31:56 -0700 (PDT)
Hi Manuel,

It seems the problem is with the context node under
which the evaluation xml/CCC/DDD[@attrib='123'][1] is
done.

If you run the following XSL to the XML, the correct
result is printed.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="text" version="1.0"
encoding="UTF-8" indent="yes"/>
	
<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>

Regards,
Mukul

--- Manuel Reyes <Manuel.Reyes@xxxxxxxxx> wrote:
> 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
> 



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

Current Thread