RE: [xsl] Converting a Batch File to XML

Subject: RE: [xsl] Converting a Batch File to XML
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Sat, 24 Jul 2004 00:19:29 +0100
It can be done using XSLT 1.0, but it's going to be pretty hard work, which
is why I advised 2.0 for this problem. I think if I were constrained to 1.0
then I would probably do it in Java instead. Of course I don't know your
project constraints.

Michael Kay 

> -----Original Message-----
> From: Garvin Franco [mailto:garvin_franco@xxxxxxxxxxx] 
> Sent: 23 July 2004 23:41
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Converting a Batch File to XML
> 
> Michael, unfortunately we are not ready to move to XSLT 2.0.
> I understand that most XSLT 2.0 engines are not quite ready 
> or are based on 
> experimental code. Is XSLT 2.0 the only solution to this 
> problem? It seems 
> that it can be done using a series of templates, but I'm 
> having problems 
> figuring out how to structure the style sheet to give me the 
> desired output.
> 
> Garvin
> 
> 
> 
> 
> 
> >From: "Michael Kay" <mhk@xxxxxxxxx>
> >Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> >Subject: RE: [xsl] Converting a Batch File to XML 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/
> >
> 
> _________________________________________________________________
> Scan and help eliminate destructive viruses from your inbound 
> and outbound 
> e-mail and attachments. 
> http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&;
> DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines 
>   Start enjoying all the benefits of MSNR Premium right now 
> and get the 
> first two months FREE*.

Current Thread