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 January 19th, 2007, 06:34 AM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default to reterieve data from XSLT file

Yaar I m trying to retreive the data from XML file i.e Price and Artist but the problem is that I cannot separate the elements selected by the node iterator ,it places both artist and price together in the one column as u c in node iterator code I m selecting both , and the output is as ,

I want only price should be in price column and artist should be in artist column

If any idea how to do ,plz reply



Regards,

Kulbir Sandhu





Price
 Artist

Bob Dylan
 Bob Dylan

10.90
 10.90

Bonnie Tyler
 Bonnie Tyler

9.90
 9.90

Dolly Parton
 Dolly Parton

9.90
 9.90

Gary Moore
 Gary Moore

10.20
 10.20

Eros Ramazzotti
 Eros Ramazzotti

9.90
 9.90










  DataTable dt = new DataTable();

        dt.Columns.Add("Price", typeof(string));

        dt.Columns.Add("Artist", typeof(string));





        XPathDocument doc = new XPathDocument(@"D:\WebSite1\kulbir\XMLXpath\Books. xml");

        XPathNavigator nav = doc.CreateNavigator();

        XPathNodeIterator iter = nav.Select("//catalog/cd/artist | //catalog/cd/price");





        while (iter.MoveNext())

        {

            DataRow dr = dt.NewRow();

            dr["Price"] = iter.Current.Value;

            dr["Artist"] = iter.Current.Value;

            dt.Rows.Add(dr);



        }

        dgr.DataSource = dt;

        dgr.DataBind();







    }

}


kulbir
 
Old January 19th, 2007, 07:01 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure why you've posted to an XSLT forum and mentioned XSLT in your title when you aren't using XSLT.

I would have thought it was pretty obvious that if you do this:

            dr["Price"] = iter.Current.Value;

            dr["Artist"] = iter.Current.Value;

then both variables will be set to the same value.

Better to do your XPath iteration over the cd elements, and then select the child artist/price elements of each cd by direct navigation.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt searching data rahulsk1947 XSLT 1 May 16th, 2007 07:14 AM
XSLT of an HTML data NEO1976 XSLT 3 July 5th, 2006 08:28 AM
Transforming XML data in an ASP file using XSLT hussainm Classic ASP XML 0 May 31st, 2006 03:21 PM
Need to format data in xslt emils XSLT 1 November 3rd, 2005 02:38 PM
Two styles one xslt file chriswiggins01 XSLT 1 May 22nd, 2005 10:21 PM





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