This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Transform flat structure into hierarchy
- From: "Scherpenzeel, Wim" <Wim dot Scherpenzeel at softwareag dot com>
- To: "'XSL-List at lists dot mulberrytech dot com'" <XSL-List at lists dot mulberrytech dot com>
- Date: Mon, 11 Mar 2002 16:13:50 +0100
- Subject: [xsl] Transform flat structure into hierarchy
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi all!
I have an XML file (see below) that has a 'flat' structure and I need to
transform it into an hierarchical structure (see below).
I am trying my best with the Muenchian method etc, but I cannot get it quite
right.
Anybody out there want to give this one a try?
Thanks
Wim
--------------------
Input file:
--------------------
<Publication>
<PublicationElements>
<ParentIndex>-1</ParentIndex>
<SelfIndex>0</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>Folderflap</LabelName>
<ElementText>
</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>0</ParentIndex>
<SelfIndex>1</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>frontpage</LabelName>
<ElementText>
</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>1</ParentIndex>
<SelfIndex>2</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>headerbox</LabelName>
<ElementText>
</ElementText>
<Functions>Pre#F#Box</Functions>
</PublicationElements>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>3</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>headertext</LabelName>
<ElementText>Navigation Systems from Nissan</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>4</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>visitbox</LabelName>
<ElementText>
</ElementText>
<Functions>Pre#F#Box</Functions>
</PublicationElements>
<PublicationElements>
<ParentIndex>4</ParentIndex>
<SelfIndex>5</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>visittext</LabelName>
<ElementText>Visit our website at: www.nissan.com Nissan reserves the
right to alter specifications and availability without notice.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>6</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>footerbox</LabelName>
<ElementText>
</ElementText>
<Functions>Pre#F#Box</Functions>
</PublicationElements>
<PublicationElements>
<ParentIndex>6</ParentIndex>
<SelfIndex>7</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>footertext</LabelName>
<ElementText>Superior brands, for the widest choice.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>8</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>dealerlogobox</LabelName>
<ElementText>
</ElementText>
<Functions>Pre#F#Box</Functions>
</PublicationElements>
<PublicationElements>
<ParentIndex>8</ParentIndex>
<SelfIndex>9</SelfIndex>
<LabelTypeName>Image</LabelTypeName>
<LabelName>logo</LabelName>
<ElementText>webdots_logo.tif</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>10</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>dealerstampbox</LabelName>
<ElementText>
</ElementText>
<Functions>Pre#F#Box</Functions>
</PublicationElements>
<PublicationElements>
<ParentIndex>10</ParentIndex>
<SelfIndex>11</SelfIndex>
<LabelTypeName>Herhaal</LabelTypeName>
<LabelName>dealeralineas</LabelName>
<ElementText>
</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>12</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>J.F. Kennedylaan 81</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>13</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>5555 XM Valkenswaard</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>14</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>The Netherlands</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>15</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>phone: +31(0)40 207 37 80</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>16</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>fax: +31(0)40 207 37 81</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>17</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>www.webdots.nl</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>0</ParentIndex>
<SelfIndex>18</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>backpage</LabelName>
<ElementText>
</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>18</ParentIndex>
<SelfIndex>19</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>textbox</LabelName>
<ElementText>
</ElementText>
<Functions>Pre#F#Box</Functions>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>20</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textheader</LabelName>
<ElementText>Nissan Navigation Systems</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>21</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textsubheader</LabelName>
<ElementText>The choice is yours</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>22</SelfIndex>
<LabelTypeName>Herhaal</LabelTypeName>
<LabelName>textalineas</LabelName>
<ElementText>
</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>23</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>Navigation has never been easier, or more enjoyable. Simple
entere your destination and let technology do the rest, ensurig that always
arive on time and relaxed.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>24</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>Whats more, navigation has never been more flexible,
because you can choose your preferred route: fastest, most sceneic, or the
one that passes your friendt's house.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>25</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>You can choose to navigate with on-screen images or voice
instructions. Or both. There are detailed colour maps with realistic
representations of the road or simple arrow and icon displays to indicate
the way.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>26</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>And you can choose to avoid road blocks and traffic
congestion - with TMC (Traffic Message Channel), with can automatically
re-plot your route on receiving a signal.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>27</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>All this is possible thanks to the new range of
state-of-the-art navigation systems specially selected by Nissan. A range
that gives you a choice of superior brands and stylish sophistication, and
comes with the quality assurance and peace of mind your expect from the
precision installation services provided by your Nissan
Dealer.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>28</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>Its also a range that matches your budget as well as your
needs. From high-end solutions such as Nissant's own Birdview, which guides
you to your destination using unique 3D images. To the more cost-effective
solutions using arrow and voice.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>29</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>Take a closer look. And think about the time you can save,
and fruxtration you can avoid, with a state-of-the art navigation system
from Nissan.</ElementText>
</PublicationElements>
</Publication>
-----------------------
Desired output file:
-----------------------
<Publication>
<PublicationElements>
<ParentIndex>-1</ParentIndex>
<SelfIndex>0</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>Folderflap</LabelName>
<ElementText></ElementText>
<PublicationElements>
<ParentIndex>0</ParentIndex>
<SelfIndex>1</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>frontpage</LabelName>
<ElementText></ElementText>
<PublicationElements>
<ParentIndex>1</ParentIndex>
<SelfIndex>2</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>headerbox</LabelName>
<ElementText></ElementText>
<Functions>Pre#F#Box</Functions>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>3</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>headertext</LabelName>
<ElementText>Navigation Systems from
Nissan</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>4</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>visitbox</LabelName>
<ElementText></ElementText>
<Functions>Pre#F#Box</Functions>
<PublicationElements>
<ParentIndex>4</ParentIndex>
<SelfIndex>5</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>visittext</LabelName>
<ElementText>Visit our
website at: www.nissan.com Nissan reserves the right to alter specifications
and availability without notice.</ElementText>
</PublicationElements>
</PublicationElements>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>6</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>footerbox</LabelName>
<ElementText></ElementText>
<Functions>Pre#F#Box</Functions>
<PublicationElements>
<ParentIndex>6</ParentIndex>
<SelfIndex>7</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>footertext</LabelName>
<ElementText>Superior
brands, for the widest choice.</ElementText>
</PublicationElements>
</PublicationElements>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>8</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>dealerlogobox</LabelName>
<ElementText></ElementText>
<Functions>Pre#F#Box</Functions>
<PublicationElements>
<ParentIndex>8</ParentIndex>
<SelfIndex>9</SelfIndex>
<LabelTypeName>Image</LabelTypeName>
<LabelName>logo</LabelName>
<ElementText>webdots_logo.tif</ElementText>
</PublicationElements>
</PublicationElements>
<PublicationElements>
<ParentIndex>2</ParentIndex>
<SelfIndex>10</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>dealerstampbox</LabelName>
<ElementText></ElementText>
<Functions>Pre#F#Box</Functions>
<PublicationElements>
<ParentIndex>10</ParentIndex>
<SelfIndex>11</SelfIndex>
<LabelTypeName>Herhaal</LabelTypeName>
<LabelName>dealeralineas</LabelName>
<ElementText></ElementText>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>12</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>J.F.
Kennedylaan 81</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>13</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>5555 XM
Valkenswaard</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>14</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>The
Netherlands</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>15</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>phone:
+31(0)40 207 37 80</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>16</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>fax:
+31(0)40 207 37 81</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>11</ParentIndex>
<SelfIndex>17</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>dealeralinea</LabelName>
<ElementText>www.webdots.nl</ElementText>
</PublicationElements>
</PublicationElements>
</PublicationElements>
</PublicationElements>
<PublicationElements>
<ParentIndex>0</ParentIndex>
<SelfIndex>18</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>backpage</LabelName>
<ElementText></ElementText>
<PublicationElements>
<ParentIndex>18</ParentIndex>
<SelfIndex>19</SelfIndex>
<LabelTypeName>Volgorde</LabelTypeName>
<LabelName>textbox</LabelName>
<ElementText></ElementText>
<Functions>Pre#F#Box</Functions>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>20</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textheader</LabelName>
<ElementText>Nissan
Navigation Systems</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>21</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textsubheader</LabelName>
<ElementText>The choice is
yours</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>22</SelfIndex>
<LabelTypeName>Herhaal</LabelTypeName>
<LabelName>textalineas</LabelName>
<ElementText></ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>23</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>Navigation has
never been easier, or more enjoyable. Simple entere your destination and let
technology do the rest, ensurig that always arive on time and
relaxed.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>24</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>What's more,
navigation has never been more flexible, because you can choose your
preferred route: fastest, most sceneic, or the one that passes your
friendt's house.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>25</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>You can choose
to navigate with on-screen images or voice instructions. Or both. There are
detailed colour maps with realistic representations of the road or simple
arrow and icon displays to indicate the way.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>26</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>And you can
choose to avoid road blocks and traffic congestion - with TMC (Traffic
Message Channel), with can automatically re-plot your route on receiving a
signal.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>27</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>All this is
possible thanks to the new range of state-of-the-art navigation systems
specially selected by Nissan. A range that gives you a choice of superior
brands and stylish sophistication, and comes with the quality assurance and
peace of mind your expect from the precision installation services provided
by your Nissan Dealer.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>28</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>It's also a
range that matches your budget as well as your needs. From high-end
solutions such as Nissant's own Birdview, which guides you to your
destination using unique 3D images. To the more cost-effective solutions
using arrow and voice.</ElementText>
</PublicationElements>
<PublicationElements>
<ParentIndex>19</ParentIndex>
<SelfIndex>29</SelfIndex>
<LabelTypeName>Tekst</LabelTypeName>
<LabelName>textalinea</LabelName>
<ElementText>Take a closer
look. And think about the time you can save, and fruxtration you can avoid,
with a state-of-the art navigation system from Nissan.</ElementText>
</PublicationElements>
</PublicationElements>
</PublicationElements>
</PublicationElements>
</PublicationElements>
</Publication>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list