使用XSL的XML从平面xml生成分层xml

时间:2018-12-13 19:50:55

标签: xml xslt

我正在尝试使用xslt从平面xml创建分层xml。

这是XML文件:

<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> 

输出:

 <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> 

在为每组编写代码时,我陷入了编写xslt逻辑的过程中,请对此提供建议。我尝试转换直到水平,但后来被击中。可以使用按键还是应该分组?

0 个答案:

没有答案