[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] flat XML to normal XML


Subject: RE: [xsl] flat XML to normal XML
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Mon, 16 May 2005 15:08:47 +0000

Today, dunno how to quit:

This is prettier, and the key-logic shorter. Since it uses keys you can get rid of the loops, and use apply-templates as well. Later today I'll follow the link another respondent posted, and may have another epiphany :-)


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>

<xsl:key match="Table" name="k-transport" use="Level"/>
<xsl:key match="Table[Level=2]" name="k-brand" use="preceding-sibling::Table[Level = 1][1]"/>
<xsl:key match="Table[Level=3]" name="k-model" use="preceding-sibling::Table[Level = 2][1]"/>


   <xsl:template match="/">
       <NewDataSet>
           <xsl:for-each select="key('k-transport', 1)">
               <xsl:variable name="t" select="."/>
               <Transport name="{Description}">
                   <xsl:for-each select="key('k-brand', $t)">
                       <Brand name="{Description}">
                           <xsl:for-each select="key('k-model', .)">
                               <Model name="{Description}">
                               </Model>
                           </xsl:for-each>
                       </Brand>
                   </xsl:for-each>
               </Transport>
           </xsl:for-each>
       </NewDataSet>
   </xsl:template>
</xsl:stylesheet>

--A

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



Current Thread