xsl-list
[Top] [All Lists]

RE: flat XML to normal XML

2005-05-16 08:34:56
Hello Mike,
  Great article :) I look forward to read it..

Regards,
Mukul

--- Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
For a worked solution to a very similar problem
(using XSLT 2.0) see:


http://www.idealliance.org/proceedings/xml04/papers/111/mhk-paper.html

Michael Kay
http://www.saxonica.com/

 

-----Original Message-----
From: Borut Bolcina [mailto:bob(_at_)najdi(_dot_)si] 
Sent: 16 May 2005 11:25
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] flat XML to normal XML

Hello list,

I wish to transform an xml which has level
information in each item 
(Table) to xml which has hierarchy as stated in
those item's element.

<DataSet

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
    <Table>
        <Level>1</Level>
        <Description>Cars</Description>
    </Table>
    <Table>
        <Level>2</Level>
        <Description>BMW</Description>
    </Table>
    <Table>
        <Level>3</Level>
        <Description>316</Description>
    </Table>
    <Table>
        <Level>3</Level>
        <Description>Z4</Description>
    </Table>
    <Table>
        <Level>2</Level>
        <Description>Citroen</Description>
    </Table>
    <Table>
        <Level>3</Level>
        <Description>C2</Description>
    </Table>
    <Table>
        <Level>3</Level>
        <Description>C4 coupe</Description>
    </Table>
    <Table>
        <Level>2</Level>
        <Description>Alfa Romeo</Description>
    </Table>
    <Table>
        <Level>3</Level>
        <Description>156</Description>
    </Table>
    <Table>
        <Level>1</Level>
        <Description>Motorcycles</Description>
    </Table>
    ...
    ...
</DataSet>


Target xml should look something like this:

<NewDataSet>
    <Transport name="Cars">
       <Brand name="BMW">
          <Model>316</Model>
          <Model>Z4</Model>
       </Brand>
       <Brand name="Citroen">
          <Model>C2</Model>
          <Model>C4 coupe</Model>
       </Brand>
       <Brand name="Alfa Romeo">
          <Model>156</Model>
       </Brand>  
    </Transport>
    <Transport name="Motorcycle">
       ...
    </Transport>
</NewDataSet>


So, based on the Level element in the source xml
for each 
Table entry, 
an appropriate subtree must be constructed and
inserted in 
target xml. 
Levels are ordered following this pattern: 
1,2,3,3,...,3,2,3,...,3,...,1,2,3,3,...,2,3,...,3

Busting my head over this for two days now, help
appreciated. 
If only I 
could find the guy who created this "flat"
xml...$%##@@!

--Bob




--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--






--~------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>