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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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.

   
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.