• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

XML with XSL generating hierarchial xml from flat xml

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

iam trying to create a hierarchial xml from a flat xml.Below is the XMLFile

<Geo>
   <Bean>
       <LEVEL1>AsiaPacific</LEVEL1>
       <DESCRIPTION>Asia Pacific</DESCRIPTION>
   <Bean>
   <DBBean>
       <LEVEL1>AsiaPacific</LEVEL1>
       <LEVEL2>India</LEVEL2>
       <DESCRIPTION>India</DESCRIPTION>
       <Bean>
   <DBBean>
       <LEVEL1>AsiaPacific</LEVEL1>
       <LEVEL2>India</LEVEL2>
<LEVEL3>NewDelhi</LEVEL2>
       <DESCRIPTION>India Capital</DESCRIPTION>
   <Bean>
<DBBean>
       <LEVEL1>AsiaPacific</LEVEL1>
       <LEVEL2>China</LEVEL2>
       <DESCRIPTION>China</DESCRIPTION>
       <Bean>
   <DBBean>
       <LEVEL1>AsiaPacific</LEVEL1>
       <LEVEL2>China</LEVEL2>
<LEVEL3>Hongkong</LEVEL2>
       <DESCRIPTION>Capital</DESCRIPTION>
   <Bean>
<Bean>
       <LEVEL1>NorthAmerica</LEVEL1>
       <DESCRIPTION>North America</DESCRIPTION>
   <Bean>
   <DBBean>
       <LEVEL1>NorthAmerica</LEVEL1>
       <LEVEL2>WashingtonDC</LEVEL2>
       <DESCRIPTION>capital</DESCRIPTION>
       <Bean>
   <DBBean>
       <LEVEL1>NorthAmerica</LEVEL1>
       <LEVEL2>Texas</LEVEL2>
<LEVEL3>aBCD</LEVEL2>
       <DESCRIPTION>Capital</DESCRIPTION>
   <Bean>
</Geo>

Output?

<geo>
<LEVEL1>AsiaPacific</Level1>
<DESCRIPTION>Asia Pacific</DESCRIPTION>
      <LEVEL2>India</Level2>
      <DESCRIPTION>India</DESCRIPTION>
            <LEVEL3>NewDelhi</Level2>
            <DESCRIPTION>India Capital</DESCRIPTION>
    <LEVEL2>China</Level2>
    <DESCRIPTION>China</DESCRIPTION>
           <LEVEL3>Honkong</Level3>
          <DESCRIPTION>Capital</DESCRIPTION>
      <LEVEL1>NorthAmerica</Level1>
<DESCRIPTION>NorthAmerica</LEVEL1>
    <LEVEL2>WashingtonDC</Level3>
    <DESCRIPTION>Capital</DESCRIPTION>
         <LEVEL3>abCD</Level2>
        <DESCRIPTION>Capital</DESCRIPTION>
</ge0>

I got stuck in middle of writing xslt logic while doing for each group,pleas advisee me on this
 
Marshal
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well: both of those XML documents are malformed. And describing the second document as "hierarchical" is extremely misleading; the only reason it looks hierarchical is that it has misleading indentation which makes it look hierarchical. In reality every element is a child of the root "geo" element so it's as flat as flat can be. The first document, which you call "flat", is more hierarchical than that.

Anyway, about that XSLT: the way to design such as thing is to state in advance how an element in the source document should be converted to an element in the target document. It's pretty clear that a <Geo> element in the source should be converted to a <geo> element in the target. What are the other rules? (Hint: I'm not asking you about XSLT code there, I'm asking about the rules.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!