[xsl] Grouping help

Subject: [xsl] Grouping help
From: charlieo0@xxxxxxxxxxx
Date: Wed, 15 Aug 2012 20:19:13 +0000 (UTC)
I have a large well-formed XML table, created from a database made up of thousands of rows. Each row has 18 cell elements. I need to transform those cells into XML for a parts list. I'm going to try and provide abbreviated samples of the input and output. I have what code I need to structure my output, I'm just stuck on properly identifying the grouping.

I need group groups of the rows together based on value in one of the cells (<cell colNum="10">). There could be ten rows with that same value in cell[10) with a value of "1". Then five rows after that where cell[10] has a value of "2". Then there could be ten rows where cell[10] has the value of "3". I need to gather all the 1's together to build a parts list item. Then all the 2's, then the 3's and so on.

<table>
<rows>
<row seq="4521">
<cell colNum="1">Partslist</cell>
<cell colNum="2">36MV0</cell>
<cell colNum="3">S-33C-425SP</cell>
<cell colNum="4">MAAMAMAMA</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 001</cell>
<cell colNum="10">1</cell>
<cell colNum="11">   1</cell>
<cell colNum="12">PAFHH </cell>
<cell colNum="13">2815</cell>
<cell colNum="14">015691733</cell>
<cell colNum="15"></cell>
<cell colNum="16">ENGINE</cell>
<cell colNum="17">1</cell>
<cell colNum="18"></cell>
</row>
<row seq="4522">
<cell colNum="1">Partslist</cell>
<cell colNum="2">06085</cell>
<cell colNum="3">12539046</cell>
<cell colNum="4">MAAA1</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 002</cell>
<cell colNum="10">2</cell>
<cell colNum="11">    </cell>
<cell colNum="12">PAFZZ </cell>
<cell colNum="13"></cell>
<cell colNum="14"></cell>
<cell colNum="15"></cell>
<cell colNum="16">SHIELD,BOTTOM</cell>
<cell colNum="17">2</cell>
<cell colNum="18"></cell>
</row>
<row seq="4523">
<cell colNum="1">Partslist</cell>
<cell colNum="2">06085</cell>
<cell colNum="3">12539045</cell>
<cell colNum="4">MAAA2</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 002</cell>
<cell colNum="10">2</cell>
<cell colNum="11">    </cell>
<cell colNum="12">PAFZZ </cell>
<cell colNum="13"></cell>
<cell colNum="14"></cell>
<cell colNum="15"></cell>
<cell colNum="16">SHIELD,CENTER</cell>
<cell colNum="17">1</cell>
<cell colNum="18"></cell>
</row>
<row seq="4524">
<cell colNum="1">Partslist</cell>
<cell colNum="2">80212</cell>
<cell colNum="3">3000064-5</cell>
<cell colNum="4">MAAAN</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 002</cell>
<cell colNum="10">2</cell>
<cell colNum="11"></cell>
<cell colNum="12">PAFZZ </cell>
<cell colNum="13">5310</cell>
<cell colNum="14">015805067</cell>
<cell colNum="15"></cell>
<cell colNum="16">WASHER,FLAT</cell>
<cell colNum="17">18</cell>
<cell colNum="18"></cell>
</row>
<row seq="4525">
<cell colNum="1">Partslist</cell>
<cell colNum="2">80212</cell>
<cell colNum="3">3000000-050325</cell>
<cell colNum="4">MAAAH</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 002</cell>
<cell colNum="10">2</cell>
<cell colNum="11">1</cell>
<cell colNum="12">PAFZZ </cell>
<cell colNum="13"></cell>
<cell colNum="14"></cell>
<cell colNum="15"></cell>
<cell colNum="16">SCREW,CAP</cell>
<cell colNum="17">2</cell>
<cell colNum="18"></cell>
</row>
<row seq="4527">
<cell colNum="1">Partslist</cell>
<cell colNum="2">80212</cell>
<cell colNum="3">4292228</cell>
<cell colNum="4">MAAMA</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 002</cell>
<cell colNum="10">2</cell>
<cell colNum="11">   3</cell>
<cell colNum="12">XC    </cell>
<cell colNum="13"></cell>
<cell colNum="14"></cell>
<cell colNum="15"></cell>
<cell colNum="16">UNIT ASSEMBLY</cell>
<cell colNum="17">1</cell>
<cell colNum="18"></cell>
</row>
<row seq="4528">
<cell colNum="1">Partslist</cell>
<cell colNum="2">9R350</cell>
<cell colNum="3">37CNAM8M</cell>
<cell colNum="4">MAAAK</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 002</cell>
<cell colNum="10">2</cell>
<cell colNum="11">   4</cell>
<cell colNum="12">PAFZZ </cell>
<cell colNum="13">5310</cell>
<cell colNum="14">015817237</cell>
<cell colNum="15"></cell>
<cell colNum="16">NUT,SELF-LOCKING</cell>
<cell colNum="17">8</cell>
<cell colNum="18"></cell>
</row>
<row seq="4532">
<cell colNum="1">Partslist</cell>
<cell colNum="2">36MV0</cell>
<cell colNum="3">10110350SSSM</cell>
<cell colNum="4">MAAMAMAAF</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 002</cell>
<cell colNum="10">3</cell>
<cell colNum="11">   8</cell>
<cell colNum="12">PAFZZ </cell>
<cell colNum="13"></cell>
<cell colNum="14"></cell>
<cell colNum="15"></cell>
<cell colNum="16">SCREW,SOCKET</cell>
<cell colNum="17">2</cell>
<cell colNum="18"></cell>
</row>
<row seq="4533">
<cell colNum="1">Partslist</cell>
<cell colNum="2">9R350</cell>
<cell colNum="3">62CNAM8M</cell>
<cell colNum="4">MAAAS</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 002</cell>
<cell colNum="10">3</cell>
<cell colNum="11">   9</cell>
<cell colNum="12">PAFZZ </cell>
<cell colNum="13">5310</cell>
<cell colNum="14">015988057</cell>
<cell colNum="15"></cell>
<cell colNum="16">NUT,SELF-LOCKING</cell>
<cell colNum="17">2</cell>
<cell colNum="18"></cell>
</row>
<row seq="4534">
<cell colNum="1">Partslist</cell>
<cell colNum="2">80212</cell>
<cell colNum="3">3000000-050200</cell>
<cell colNum="4">MAAAG</cell>
<cell colNum="5">01</cell>
<cell colNum="6">P</cell>
<cell colNum="7">6EL</cell>
<cell colNum="8">0</cell>
<cell colNum="9">0100 002</cell>
<cell colNum="10">3</cell>
<cell colNum="11">  10</cell>
<cell colNum="12">PAFZZ </cell>
<cell colNum="13">5305</cell>
<cell colNum="14">015917568</cell>
<cell colNum="15"></cell>
<cell colNum="16">SCREW,CAP,HEXAGON</cell>
<cell colNum="17">8</cell>
<cell colNum="18"></cell>
</row>
</rows>
</table>

Output:

<category>
  <item>
   <qty>1</qty>
   <location>36MV0</location>
   <partno>S-33C-425SP</partno>
    <name>ENGINE</name>
   </item>
</category>
<category>    
   <item>
      <qty>2</qty>
      <location>06085</location>
      <partno>12539046</partno>
      <name>SHIELD,BOTTOM</name>
    </item>
   <item>
      <qty>1</qty>
      <location>06085</location>
      <partno>12539045</partno>
      <name>SHIELD,CENTER</name>
   </item>
   <item>
      <qty>18</qty>
      <location>80212</location>
      <partno>3000064-5</partno>
      <name>WASHER,FLAT</name>
   <item>
   <item>
      <qty>2</qty>
      <location>80212</location>
      <partno>3000000-050325</partno>
      <name>SCREW,CAP</name>
   </item>
    <item>
      <qty>1</qty>
      <location>80212</location>
      <partno>4292228</partno>
       <name>UNIT ASSEMBLY</name>
    </item>
    <item>
      <qty>8</qty>
      <location>9R350</location>
      <partno>37CNAM8M</partno>
      <name>NUT,SELF-LOCKING</name>
   </item>
</category>
<category>    
  <item>
    <qty>2</qty>
    <location>36MV0</location>
    <partno>10110350SSSM</partno>
    <name>SCREW,SOCKET</name>
  </item>
  <item>
    <qty>2</qty>
    <location>9R350</location>
    <partno>62CNAM8M</partno>
    <name>NUT,SELF-LOCKING</name>
 </item>
 <item>
    <qty>8</qty>
    <location>80212</location>
    <partno>3000000-050200</partno>
    <name>SCREW,CAP,HEXAGON</name>
 </item>
</category>

I've written this, but my output isn't what I'm wanting or expecting.

 <xsl:template match="table">
   <xsl:for-each-group select="*" group-by="cell[@colNum='10']">
     
<xsl:for-each select="current-group()">
  <category>

 STRUCTURE CELLS TO PARTS LIST .. . . .;


  </category>



</xsl:for-each-group>



C. Flanders

Current Thread