XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Kalyani YemcheSubject: Transform a XML file with simple type nodes to complex type nodes
Author: Kalyani Yemche
Date: 05 Apr 2005 09:49 AM
Hi ,
I am trying to transform following file to a file with complex nodes.
The source file contains all the info in two simple records and I want it in a linked format.
For example, here for each header there may be many manufacturers linked with it,
for each manufacturer, there may be many product types and so on till individual items represented by <item> tags.
I am new to XSLT but still I tried a lot.Please do help me if any one can.


Source file:


<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table>
<headervalue>54</headervalue>
<manufid>1</manufid>
<manufname>Manuf1</manufname>
<headoffice>HO1</headoffice>
<productid>1</productid>
<description>Desc1</description>
<dateofmfg>2004-08-05</dateofmfg>
<itemprice>300.0000</itemprice>
</Table>
<Table>
<headervalue>54</headervalue>
<manufid>1</manufid>
<manufname>Manuf2</manufname>
<headoffice>HO1</headoffice>
<productid>2</productid>
<description>Desc2</description>
<dateofmfg>2004-08-05</dateofmfg>
<itemprice>300.0000</itemprice>
</Table>
</NewDataSet>

Required output file:

<?xml version="1.0"?>
<root>
<header value="54">
<productManufacturer manufid="1" manufname="Manuf1" headOffice="HO1">
<productType productid="1" description="Desc1">
<productItem>
<item dateOfMfg="08/01/2004" price="300" />
<item dateOfMfg="08/15/2004" price="300" />
<item dateOfMfg="08/15/2004" price="310" />
</productItem>
</productType>
<productType productid="2" description="Desc2">
<productItem>
<item dateOfMfg="08/01/2004" price="300" />
<item dateOfMfg="08/15/2004" price="300" />
<item dateOfMfg="08/15/2004" price="310" />
</productItem>
</productType>
</productManufacturer>
</header>
</root>

Thanks in advance,

Kalyani

Posttop
(Deleted User) Subject: Transform a XML file with simple type nodes to complex type nodes
Author: (Deleted User)
Date: 05 Apr 2005 11:24 AM
your tansformation is basically a grouping issue, you need to group on manufacture id
for the transformation.It is not very straight forward in XSLT 1, you need to create
a nodeset contains unique element first, then iterate on this nodeset to
do further transformation. It is much easier to do grouping in XSLT 2 using xsl:for-each-group.
Stylus Studio support both XSLT 1 and XSLT 2.

In the past, we have many people ask simmilar question in this forum, if you
search 'grouping' here, you will find some interesting thread that could help
you with your task.

Let me know if you need further help.

song.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.