I have an XML file created with VorteXML. In the file, I have the following tree structure:
<Investment Category>
<Subcategory name="Somename">
<Industry>
<Companies>
<Shares>
<Price>
<Current_Value>
<etc...>
</Companies>
<Industry_Totals> Data </Industry_Totals>
</Industry>
</Subcategory>
</Investment_ Category>

Later in the XML file, there are the Subcategory Totals, for example <Subcategory_Total name="Total Somename">

Due to a problem with VorteXML, the program does not create XML when the subcategory total section is nested where it shoud be. The problem I have is when my XSL is creating the HTML, I need the subcategory totals to be inserted right before the </Subcategory> tag. Since I need to match up the proper subcategory total with the proper subcategory section (there can be 7, 8, or 9, depending on the client, meaning I can't hardcode each set in), how do I match up one set of elements with another? Here is an abbreviated sample of the XML file, showing two of my subcategories. I need to get the subtotal for the CONSUMER DURABLES to be at the end of the CONSUMER DURABLES subcategory section and the same for the CONSUMER NON-DURABLES. Any ideas?

<total_equities>
<tot_equ_cost>13435407.60</tot_equ_cost>
<tot_equ_value>15288742.90</tot_equ_value>
</total_equities>
<subcategory name="CONSUMER NON-DURABLES">
<industry name="BEVERAGES">
<companies>
<shares>9400</shares>
<company_name>PEPSIAMERICAS INC</company_name>
<purch_avg_cost>12.62</purch_avg_cost>
<purch_total_cost>118672.40</purch_total_cost>
</companies>
<industry_total>
<industry_name>TOTAL BEVERAGES</industry_name>
<industry_cost>118672.40</industry_cost>
<industry_value>147580.00</industry_value>
</industry_total>
</industry>
<industry name="COSMETICS">
<companies>
<shares>1600</shares>
<company_name>ALBERTO CULVER CO</company_name>
<purch_avg_cost>20.53</purch_avg_cost>
<purch_total_cost>32844.49</purch_total_cost>
</companies>
<companies>
<shares>4200</shares>
<comp_name>INTERNATIONAL FLAVORS</comp_name>
<purch_avg_cost>21.89</purch_avg_cost>
<purch_total_cost>91917.98</purch_total_cost>
</companies>
<industry_total>
<industry_name>TOTAL COSMETICS</industry_name>
<industry_cost>124762.47</industry_cost>
<industry_value>184230.00</industry_value>
<industry_percent>1.1</industry_percent>
<industry_income>3048.00</industry_income>
<industry_yield>1.7</industry_yield>
</industry_total>
</industry>
</subcategory>
<subcategory name="CONSUMER DURABLES">
<industry name="AUTOMOTIVE EQUIPMENT">
<companies>
<shares>3700</shares>
<company_name>CUMMINS INC</company_name>
<purch_avg_cost>42.31</purch_avg_cost>
<purch_total_cost>156553.24</purch_total_cost>
</companies>
<companies>
<shares>5500</shares>
<company_name>HUBBELL INC</company_name>
<purch_avg_cost>26.70</purch_avg_cost>
<purch_total_cost>146831.98</purch_total_cost>
<current_price>29.13</current_price>
<current_value>160215.00</current_value>
<port_percent>1.0</port_percent>
<income>7260.00</income>
<current_yield>4.5</current_yield>
</companies>
<industry_total>
<industry_name>TOTAL AUTOMOTIVE EQUIPMENT</industry_name>
<industry_cost>662449.91</industry_cost>
<industry_value>722386.00</industry_value>
</industry_total>
</industry>
<industry name="TEXTILES & SHOES">
<companies>
<shares>5700</shares>
<company_name>PHILLIPS VAN HEUSEN</company_name>
<purch_avg_cost>14.56</purch_avg_cost>
<purch_total_cost>82964.64</purch_total_cost>
</companies>
<companies>
<shares>6400</shares>
<company_name>RUSSELL CORP</company_name>
<purch_avg_cost>15.34</purch_avg_cost>
<purch_total_cost>98183.24</purch_total_cost>
</companies>
<industry_total>
<industry_name>TOTAL TEXTILES & SHOES</industry_name>
<industry_cost>181147.88</industry_cost>
<industry_value>193629.00</industry_value>
</industry_total>
</industry>
</subcategory>
<total_subcategory>
<total_subcategory_name>TOTAL CONSUMER NON-DURABLES</total_subcategory_name>
<total_subcategory_cost>3202919</total_subcategory_cost>
<total_subcategory_value>3800868</total_subcategory_value>
</total_subcategory>
<total_subcategory>
<total_subcategory_name>TOTAL CONSUMER DURABLES</total_subcategory_name>
<total_subcategory_cost>958340</total_subcategory_cost>
<total_subcategory_value>1068607</total_subcategory_value>
</total_subcategory>