Grouping already grouped records and filling information from group-head with XSL 1.0
===

I am trying to transform an XML output from our accounting system into an XML that can be imported into Access. Unfortunately Access only accepts XSL 1.0 for transformation, so I have asked already for help in transforming a XSL 2.0 solution into something that works under XSL 1.0. ([Grouping problem][1]). The solution there worked perfectly for what I thought I needed for the Access import.

The Access import works now but I realize the data is in a form that is still not really usable. The data consists of header rows and sub-rows, which are not filled with the header data. But to aggregate meaningfully, the data would need to be filled.
	
	DBCDATE     |DBBCPARTY         |DBCVCHTYPE     |DBCVCHNO   |DBCVCHREF    
	1-Apr-2011  |                  |Stock Journal  |1          |             
				|ME KN YARN B      |               |           |             
				|ME KN YARN G      |               |           |             
				|ME KN YARN I      |               |           |             
	3-Apr-2011  |                  |Stock Journal  |2          |903          
				|TIB Raw Wool      |               |           |             
				|ME KN YARN D      |               |           |             

The fields from the header row would need to be copied down also into the sub-rows: **DBCDATE, DBCVCHTYPE, DBCVCHNO, DBCNARR**.

I could do this with some VBA programming in Access or even export the data into Excel and apply some formulas, but the data is quite large and we are looking into extracting even more. And it would be less flexible. Also, the question probably goes into the direction of grouping an already grouped XML even more (now it is grouped into importable rows in form of the InventoryDaybook tag structure.

So this was the original XML:

	<ENVELOPE>
	  <DBCFIXED>  <DBCDATE>1-Apr-2011</DBCDATE>
		<DBCPARTY></DBCPARTY>
	  </DBCFIXED>
	  <DBCVCHTYPE>Stock Journal</DBCVCHTYPE>
	  <DBCVCHNO>1</DBCVCHNO>
	  <DBCVCHREF></DBCVCHREF>
	  <DBCSTNO></DBCSTNO>
	  <DBCSERVICETAXNO></DBCSERVICETAXNO>
	  <DBCPANNO></DBCPANNO>
	  <DBCCSTNO></DBCCSTNO>
	  <DBCNARR>Opening balance transfar</DBCNARR>
	  <DBCQTY>0.000 Kg</DBCQTY>
	  <DBCRATE></DBCRATE>
	  <DBCAMOUNT></DBCAMOUNT>
	  <DBCADDLCOST></DBCADDLCOST>
	  <DBCGROSSAMT></DBCGROSSAMT>
	  <DBCLEDAMT></DBCLEDAMT>
	  <DBCFIXED>  <DBCDATE></DBCDATE>
		<DBCPARTY>ME KN YARN BL 1</DBCPARTY>
	  </DBCFIXED>
	  <DBCVCHTYPE></DBCVCHTYPE>
	  <DBCVCHNO></DBCVCHNO>
	  <DBCVCHREF></DBCVCHREF>
	  <DBCSTNO></DBCSTNO>
	  <DBCSERVICETAXNO></DBCSERVICETAXNO>
	  <DBCPANNO></DBCPANNO>
	  <DBCCSTNO></DBCCSTNO>
	  <DBCNARR></DBCNARR>
	  <DBCQTY>0.150 Kg</DBCQTY>
	  <DBCRATE>566.00/Kg</DBCRATE>
	  <DBCAMOUNT>-84.90</DBCAMOUNT>
	  <DBCADDLCOST></DBCADDLCOST>
	  <DBCGROSSAMT></DBCGROSSAMT>
	  <DBCLEDAMT></DBCLEDAMT>
	</ENVELOPE>

This is the XSL (XSLT 1.0), slightly changed from the solution:

	<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	   <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
	   <xsl:key name="records" match="ENVELOPE/*[not(self::DBCFIXED)]" use="generate-id(preceding-sibling::DBCFIXED[1])" />
	   <xsl:template match="/ENVELOPE">
		  <Data>
			 <xsl:apply-templates select="DBCFIXED" />
		  </Data>
	   </xsl:template>

	   <xsl:template match="DBCFIXED">
		  <InventoryDaybook>
			 <xsl:copy-of select="./*" />
			 <xsl:apply-templates select="key('records', generate-id())" />
		  </InventoryDaybook>
	   </xsl:template>

	   <xsl:template match="@*|node()">
		  <xsl:copy>
			 <xsl:apply-templates select="@*|node()"/>
		  </xsl:copy>
	   </xsl:template>
	</xsl:stylesheet>

Is there a way to do this in XSL? Also I was wondering if this means to kind of transform the returned XML again? Something like in this solution? [Solution to double transformation question][3]

I realize that I am asking twice on the forum for the same larger problem but I am really grateful for your help on this.

  [1]: http://stackoverflow.com/questions/11625288/grouping-of-a-well-defined-flat-xml-for-access-import-xslt-1-0
  [2]: http://i.stack.imgur.com/dTsOy.jpg
  [3]: http://stackoverflow.com/questions/8822956/transforming-transformed-xml-with-xsl