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 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Brad ThackerSubject: Convert linefeed-separated text file to nested XML
Author: Brad Thacker
Date: 16 Jul 2008 12:22 PM
I just installed Stylus Studio and am attempting to use it to convert a file of linefeed-separated text records to nested XML. The structure of the initial text file looks like this:

0 | item#1 |..| ..| ..| ..| ... (other fields)
1 | item#2 |..| ..| ..| ..|
2 | item#3 |..| ..| ..| ..|
2 | item#4 |..| ..| ..| ..|
1 | item#5 |..| ..| ..| ..|

and I need to convert it to a nested XML structure in which the level of nesting is determined by the first field in the pipe-delineated file. The output should look like this:

<record level="0"> <item>item#1</item>
<record level="1"><item>item#2</item>
<record level="2"><item>item#3</item>
</record>
<record level="2"><item>item#4</item>
</record>
</record>
<record level="1"><item>item#5</item>
</record>
</record>

I read through Chapter 3 of the users manual that describes how to convert text to XML, but did not find any information that hinted at how to do this nesting. What I end up with is a flat structure:

<record level="0"><item>item#1</item></record>
<record level="1"><item>item#2</item></record>
<record level="2"><item>item#3</item></record>
<record level="2"><item>item#4</item></record>
<record level="1"><item>item#5</item></record>

Is it possible to use the tool set native to Stylus Studio to get the proper nesting, or do I need to perform an XSLT conversion on the flat XML structure above to get it?

I did find a set of XSLT conversion templates that can take the flat XML structure and convert it to the nested one, but I would prefer to do the complete transformation in one step, if possible.

Thanks for your help.
Brad

Posttop
Minollo I.Subject: Convert linefeed-separated text file to nested XML
Author: Minollo I.
Date: 16 Jul 2008 12:51 PM
You do need a post-processing step based on XQuery or XSLT to generate the structure you are looking for.

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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.