RE: [xsl] Converting a Batch File to XML

Subject: RE: [xsl] Converting a Batch File to XML
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 23 Jul 2004 22:04:05 +0100
This kind of thing is very much easier using XSLT 2.0

* use the unparsed-text() function to read the text file

* split it into individual lines using the tokenize() function

* parse each line using xsl:analyze-string

* arrange it into a hierarchical structure using xsl:for-each-group

Michael Kay
 

> -----Original Message-----
> From: Garvin Franco [mailto:garvin_franco@xxxxxxxxxxx] 
> Sent: 23 July 2004 20:31
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Converting a Batch File to XML 
> 
> Hello folks, looking for some insight here. Need to know if 
> this is possible 
> using XSLT. I prefer using a style sheet as I may use this 
> style sheet in a 
> Java,C++ and .NET environment.
> I have a flat file that I need to convert to an XML 
> structure. Now I can do 
> this if the records in the file had the same structure, this 
> is fairly 
> simple. But my source fixed length file has mutliple records 
> that need to be 
> associated to a single node on the target xml. For example, 
> my file is 
> structured as follows...
> 
> FROM
> Source: Fixed Length Data
> 
> H-A-HEADER........
> I-AN-ITEM-1........
> I-AN-ITEM-2........
> S-A-SUMMARY-1..
> I-AN-ITEM-3........
> S-A-SUMMARY-2..
> 
> (Note: each record is on a new line)
> 
> TO
> Target: XML Data
> 
> <someRoot>
>   <header>
>     <headerTag>A-HEADER</headerTag> <!-- note the header ID,'H',not 
> transformed -->
>   </header>
>   <record>
>     <order>
>       <item>
>          <itemTag>AN-ITEM-1</itemTag>  <!-- note the item ID,'I',not 
> transformed -->
>       </item>
>       <item>
>          <itemTag>AN-ITEM-2</itemTag>
>       </item>
>       <summary>
>          <summaryTag>A-SUMMARY-1</summaryTag> <!-- note 
> summary ID,'S',not 
> transformed -->
>       </summary>
>     </order>
>    </record>
>    <record>
>      <order>
>         <item>
>           <itemTag>AN-ITEM-3</itemTag>
>         </item>
>         <summary>
>            <summaryTag>A-SUMMARY-2</summaryTag>
>         </summary>
>       </order>
>     <record>
> </someRoot>
> 
> Would appreciate any thoughts or samples that you can provide 
> to help me 
> achieve this. I believe recursion will be needed here, right? 
> Also, it may 
> not be efficient to load the entire file into a variable, then start 
> processing from there. These are some of the things I thought 
> about, but I'm 
> not to sure how to start.
> Thanking you in advance for any ideas. Also, if this is not 
> the forum for 
> this, please advise...
> 
> Regards
> Garvin
> 
> _________________________________________________________________
> Don't just search. Find. Check out the new MSN Search! 
> http://search.msn.click-url.com/go/onm00200636ave/direct/01/

Current Thread