[xsl] Can I group in three levels?

Subject: [xsl] Can I group in three levels?
From: "Felix Garcia" <fnmtool@xxxxxxxxxxx>
Date: Thu, 07 Nov 2002 07:21:20 +0000
I have problems to generate the desired output of an XML using XSL. I want to group in three levels


This is the XML to transform:


<?xml version="1.0" encoding="UTF-8"?>
<ROWSET>
  <ROW>
     <ID>27835</ID>
     <NUMBER>29715</NUMBER>
     <PHONE>09876</PHONE>
     <ACT>ACT34</ACT>
  </ROW>
  <ROW>
     <ID>27835</ID>
     <NUMBER>29716</NUMBER>
     <PHONE>62784</PHONE>
     <ACT>ACT87</ACT>
  </ROW>
  <ROW>
     <ID>27835</ID>
     <NUMBER>29716</NUMBER>
     <PHONE>3333333</PHONE>
     <ACT>ACT23</ACT>
  </ROW>
  <ROW>
     <ID>27835</ID>
     <NUMBER>29716</NUMBER>
     <PHONE>3333333</PHONE>
     <ACT>ACT111</ACT>
  </ROW>
</ROWSET>



First I want to group in a first level with the same ID,NUMBER. Inside of this first group, a second group with a second

group with PHONE. And finally a third group, inside the second group with ACT. I'm not sure if I'm explainig clear.


This is my XSL, that doesn't work


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0" xmlns:xalan="http://xml.apache.org/xslt";>
<xsl:key name="level1" match="ROW" use="concat(ID,' ',NUMBER)" />
<xsl:template match="ROWSET">
<ROOT>
<xsl:for-each select="ROW[count(. | key('level1', concat(ID,' ',NUMBER))[1]) = 1]">
<xsl:sort select="ID" />
<ID><xsl:value-of select="ID" /></ID>
<NUM><xsl:value-of select="NUMBER" /></NUM>
<xsl:for-each select="key('level1', concat(ID,' ',NUMBER))">
<xsl:sort select="PHONE" />
<PHONE_DATA>
<PHONE><xsl:value-of select="PHONE" /></PHONE>
<ACT_DATA>
????????
</ACT_DATA>
</PHONE_DATA>
</xsl:for-each>
</xsl:for-each>
</ROOT>
</xsl:template>
</xsl:stylesheet>


My desired output for the first XML is:


<?xml version="1.0" encoding="UTF-16" ?> <ROOT xmlns:xalan="http://xml.apache.org/xslt";> <ID>27835</ID> <NUM>29715</NUM> <PHONE_DATA> <PHONE>09876</PHONE> <ACT_DATA> <ACT>ACT34</ACT> </ACT_DATA> </PHONE_DATA> <ID>27835</ID> <NUM>29716</NUM> <PHONE_DATA> <PHONE>3333333</PHONE> <ACT_DATA> <ACT>ACT23</ACT> </ACT_DATA> <ACT_DATA> <ACT>ACT111</ACT> </ACT_DATA> </PHONE_DATA> <PHONE_DATA> <PHONE>62784</PHONE> <ACT_DATA>ACT87</ACT_DATA> </PHONE_DATA> </ROOT>

How could I do this?




_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread