xsl-list
[Top] [All Lists]

RE: flat XML to normal XML

2005-05-16 08:08:47
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/


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