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 September 2nd, 2004, 05:06 PM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Transform XML to XML using XSLT



Hi folks!

I need some help/pointers to solve the following problem.

I have an XML file, which I would like to convert to a different layout/format and the output will be another XML file. I want to achieve this using XSLT. The input file structure is build using C# code in .Net platform. Once the tag structure is formed, it is fed to the XSLT for transformation and the transformed output is written to a file.

The input XML file looks exactly like this:
---------------------------------------
<ExportData>
- <Terminal>

- <Element>
    <SPLC>234234789</SPLC>
    <Name>Terminal234</Name>
    <TCN />
    <Address>1000 1st street</Address>
    <Address>Suite 200</Address>
    <City>NYC</City>
    <State>NY</State>
    <Country>USA</Country>
  - <Product>
    <ProductCode>A25</ProductCode>
    <ProductName>Aviation Fuel - New</ProductName>
  </Product>
  - <Consignee>
    - <Element>
       <Number>103008</Number>
       <Name>103008</Name>
    </Element>
  </Consignee>
</Element>

- <Element>
    <SPLC>234234789</SPLC>
    <Name>Terminal234</Name>
    <TCN />
    <Address>1000 1st street</Address>
    <Address>Suite 200</Address>
    <City>NYC</City>
    <State>NY</State>
    <Country>USA</Country>
  - <Product>
    <ProductCode>A30</ProductCode>
    <ProductName>Premium gasoline</ProductName>
  </Product>
  - <Consignee>
    - <Element>
      <Number>12345678998765</Number>
      <Name>New consignee</Name>
    </Element>
  </Consignee>
  </Element>

 </Terminal>
</ExportData>
----------------------------------------

and I need to convert the above XML to another XML which should look like the following:

<ExportData>
-<Terminal>
 -<Element>
    <SPLC>234234789</SPLC>
    <Name>Terminal234</Name>
    <TCN />
    <Address>1000 1st street</Address>
    <Address>Suite 200</Address>
    <City>NYC</City>
    <State>NY</State>
    <Country>USA</Country>
  - <Product>
    -<Element>
      <ProductCode>A25</ProductCode>
      <ProductName>Aviation Fuel - New</ProductName>
    </Element>
    -<Element>
      <ProductCode>A30</ProductCode>
      <ProductName>Premium gasoline</ProductName>
    </Element>
  </Product>
   -<Consignee>
     -<Element>
       <Number>103008</Number>
       <Name>103008</Name>
     </Element>
     -<Element>
      <Number>12345678998765</Number>
      <Name>New consignee</Name>
     </Element>
   </Consignee>
 </Element>
 </Terminal>
</ExportData>
---------------------------------
Please help me to write an XSLT, which can perform the above explained task.

Thanks in advance.

 
Old September 2nd, 2004, 05:20 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This is a grouping problem: read all about it at http://www.jenitennison.com/xslt/grouping

Michael Kay
http://www.saxonica.com/

Michael Kay
http://saxon.sf.net/
 
Old September 7th, 2004, 02:13 PM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a bunch for your valuable pointer.






Similar Threads
Thread Thread Starter Forum Replies Last Post
XML/XSLT Transform Error in ASP kwilliams Classic ASP XML 2 October 9th, 2007 02:26 AM
How do I transform XSLT without the <?xml?> tag? nadavvin XSLT 4 June 10th, 2007 09:25 AM
Can 1 xslt transform an xml doc into 2 text files Raju Sarode XSLT 7 November 3rd, 2006 04:10 PM
Transform XML with XSLT in JavaScript Mozilla Spankmaster79 Javascript 3 January 18th, 2006 07:31 AM
XSLT read through XML to transform another XML dendenx2 XSLT 8 July 7th, 2005 08:18 PM





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