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 March 1st, 2013, 08:08 PM
Authorized User
Join Date: Mar 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to convert unfixed row and column from xml to xml


I have the below xml file that I would like to convert. I need to form a complete record by extracting the column data from each row. For example: the below will found a complete record.

first row.col_2, second row.col_0, second row.col_1, second row.col_2, third row.col_0, etc.

I am trying to accomplish this in xslt 1.0. I know it might be easier in 2.0 but this is what we currently have in house.

Please help if you know how to do this...

<col_n>this could be the last data</col_n>
<col_0>03/21/2012 0:00</col_0>
<col_0>03/21/2012 0:00</col_0>
<col_2>k 00 00</col_2>
<col_3>k 00 00</col_3>
<col_4>k 00 00</col_4>
<col_5>k 00 00</col_5>
<col_6>k 00 00</col_6>
<col_7>k 00 20</col_7>
Old March 2nd, 2013, 06:48 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

You can use simple xpath to pick any particular item you want from a row or column.

e.g. For the first row, and third column you would use "/root/row[1]/*[3]" (this would select col_2 in your example above, as your first column is col_0).

Without seeing how you want your output formatted etc it hard to give more advice than that.
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Old March 2nd, 2013, 03:43 PM
Authorized User
Join Date: Mar 2009
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to convert unfixed row and column from xml to xml


Thank you so much for responding. Below is my desire output. I would like to loop through the rows to extract the information then for a complete record in the xml.

<RECORD ID="first row.col_2 DATA" CN="second row.col_1 data">
<VAL V="second row.col_2 data" BDATE="second row.col_0 data"/>
<VAL V="third row.col_2" BDATE="third row.col_0 data"/>

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert XML to CSV with XML field names as column headers? swheeler XSLT 10 February 10th, 2012 11:18 AM
XSLT for converting column based xml to row based one sayusekhar XSLT 4 March 8th, 2011 08:20 AM
Convert 1 big XML to multiple smaller XML victorcorey XSLT 1 March 20th, 2008 05:59 AM
Convert XML to XML template question bonekrusher XSLT 3 July 12th, 2007 07:47 AM
convert XML to XMl - Another Namespace question bonekrusher XSLT 2 July 10th, 2007 07:32 AM

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