Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2011, 03:21 AM
Registered User
 
Join Date: Nov 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting a value from XML using XPATH

I have touble getting a certain value from a XML. I do not know it it is possble but perhaps someone can help me.

The value that I have is 'XYZ987' or 'ABC123'. In the real XML I have around 1000 <group>. There is always two <row> under each <rows>, and the first is CUST and second is PROD. However there can be one or many <col>

The value that I want to fetch is the last value under CUST, eg when using 'XYZ987' I want value 91.0 or when using 'ABC123' I want value 9.0

Is this possible?

The XML:
Code:
<group>
	<header>
		<row>
			<col>XYZ987</col>
			<col></col>
			<col></col>
			<col></col>
			<col></col>
			<col></col>
		</row>
	</header>
	<rows>
		<row>
			<col>CUST</col>
			<col datatype="number" decimals="0">47.0</col>
			<col datatype="number" decimals="0">49.0</col>
			<col datatype="number" decimals="0">16.0</col>
			<col datatype="number" decimals="0">36.0</col>
			<col datatype="number" decimals="0">91.0</col> <- Value I want to fetch
		</row>
		<row>
			<col>PROD</col>
			<col datatype="number" decimals="0">46.0</col>
			<col datatype="number" decimals="0">41.0</col>
			<col datatype="number" decimals="0">14.0</col>
			<col datatype="number" decimals="0">35.0</col>
			<col datatype="number" decimals="0">92.0</col>
		</row>
	</rows>
</group>
<group>
	<header>
		<row>
			<col>ABC123</col>
			<col></col>
			<col></col>
			<col></col>
			<col></col>
			<col></col>
		</row>
	</header>
	<rows>
		<row>
			<col>CUST</col>
			<col datatype="number" decimals="0">1.0</col>
			<col datatype="number" decimals="0">3.0</col>
			<col datatype="number" decimals="0">4.0</col>
			<col datatype="number" decimals="0">7.0</col>
			<col datatype="number" decimals="0">9.0</col>
		</row>
		<row>
			<col>PROD</col>
			<col datatype="number" decimals="0">46.0</col>
			<col datatype="number" decimals="0">48.0</col>
			<col datatype="number" decimals="0">16.0</col>
			<col datatype="number" decimals="0">36.0</col>
			<col datatype="number" decimals="0">91.0</col>
		</row>
	</rows>
</group>
 
Old November 10th, 2011, 04:21 AM
Registered User
 
Join Date: Nov 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I forgott the <root> element of course.

however I think I found a solution
/root/group/header/child::row[col='XYZ987']/../following-sibling::*/child::row[col='CUST']/col[last()]
 
Old November 10th, 2011, 08:13 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Code:
//row[col[1]=$param]/col[last()]
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old November 10th, 2011, 09:19 AM
Registered User
 
Join Date: Nov 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry no because that would give me:
Code:
<group>
	<header>
		<row>
			<col>XYZ987</col>
			<col></col>
			<col></col>
			<col></col>
			<col></col>
			<col></col> <- this value 
		</row>
	</header>
	<rows>
		<row>
			<col>CUST</col>
			<col datatype="number" decimals="0">47.0</col>
			<col datatype="number" decimals="0">49.0</col>
			<col datatype="number" decimals="0">16.0</col>
			<col datatype="number" decimals="0">36.0</col>
			<col datatype="number" decimals="0">91.0</col>
		</row>
		<row>
			<col>PROD</col>
			<col datatype="number" decimals="0">46.0</col>
			<col datatype="number" decimals="0">41.0</col>
			<col datatype="number" decimals="0">14.0</col>
			<col datatype="number" decimals="0">35.0</col>
			<col datatype="number" decimals="0">92.0</col>
		</row>
	</rows>
</group>
But I solved it





Similar Threads
Thread Thread Starter Forum Replies Last Post
create XML using XPath and XSL sonaliag1 XML 3 May 24th, 2011 06:35 AM
Using Xpath on an XML wrapped in CDATA akentanaka XSLT 4 March 11th, 2009 05:26 AM
Read XML to DataSet with XPath? striker9 ASP.NET 2.0 Basics 1 July 25th, 2006 03:30 AM
System.Xml.XmlException with XPath ronaldcampfaso C# 1 December 31st, 2005 03:55 AM
Using XPath to get a certain field from XML (UPS) taleriana XML 4 May 24th, 2005 08:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.