XSLT - convert overly nested XML to a HTML table, how to reference elements in a loop
I'm receiving this xml (actually this is a converted EDI/EDIFACT message):

<!-- language: lang-xml -->

    <EDIFACT>
	<SLSFCT>
		<DTM>
			<DTM01>
				<DTM0101 decode="Date, as at">
					<!--2005: Date/time/period qualifier-->183</DTM0101>
				<DTM0102>
					<!--2380: Date/time/period-->140112</DTM0102>
				<DTM0103 decode="DDMMYY">
					<!--2379: Date/time/period format qualifier-->2</DTM0103>
			</DTM01>
		</DTM>
		<GROUP_5>
			<DTM>
				<DTM01>
					<DTM0101 decode="Horizon period">
						<!--2005: Date/time/period qualifier-->323</DTM0101>
					<DTM0102>
						<!--2380: Date/time/period-->0112</DTM0102>
					<DTM0103 decode="YYMM">
						<!--2379: Date/time/period format qualifier-->609</DTM0103>
				</DTM01>
			</DTM>
			<GROUP_6>
				<LIN>
					<LIN01>
						<!--1082: LINE ITEM NUMBER-->1</LIN01>
					<LIN03>
						<LIN0301>
							<!--7140: Item number-->88840</LIN0301>
						<LIN0302 decode="Buyer's item number">
							<!--7143: Item number type, coded-->IN</LIN0302>
						<LIN0304 decode="Assigned by buyer or buyer's agent">
							<!--3055: Code list responsible agency, coded-->92</LIN0304>
					</LIN03>
				</LIN>
				<PIA>
					<PIA01 decode="Additional identification">
						<!--4347: PRODUCT ID. FUNCTION QUALIFIER-->1</PIA01>
					<PIA03>
						<PIA0301>
							<!--7140: Item number-->0</PIA0301>
						<PIA0302 decode="Supplier's article number">
							<!--7143: Item number type, coded-->SA</PIA0302>
						<PIA0304 decode="Assigned by seller or seller's agent">
							<!--3055: Code list responsible agency, coded-->91</PIA0304>
					</PIA03>
				</PIA>
				<GROUP_7>
					<QTY>
						<QTY01>
							<QTY0101 decode="Cumulative quantity, actual estimated">
								<!--6063: Quantity qualifier-->138</QTY0101>
							<QTY0102>
								<!--6060: Quantity-->10</QTY0102>
							<QTY0103>
								<!--6411: Measure unit qualifier-->PCE</QTY0103>
						</QTY01>
					</QTY>
				</GROUP_7>
			</GROUP_6>
			<GROUP_6>
				<LIN>
					<LIN01>
						<!--1082: LINE ITEM NUMBER-->1</LIN01>
					<LIN03>
						<LIN0301>
							<!--7140: Item number-->884530</LIN0301>
						<LIN0302 decode="Buyer's item number">
							<!--7143: Item number type, coded-->IN</LIN0302>
						<LIN0304 decode="Assigned by buyer or buyer's agent">
							<!--3055: Code list responsible agency, coded-->92</LIN0304>
					</LIN03>
				</LIN>
				<PIA>
					<PIA01 decode="Additional identification">
						<!--4347: PRODUCT ID. FUNCTION QUALIFIER-->1</PIA01>
					<PIA03>
						<PIA0301>
							<!--7140: Item number-->8888774319981</PIA0301>
						<PIA0302 decode="Supplier's article number">
							<!--7143: Item number type, coded-->SA</PIA0302>
						<PIA0304 decode="Assigned by seller or seller's agent">
							<!--3055: Code list responsible agency, coded-->91</PIA0304>
					</PIA03>
				</PIA>
				<GROUP_7>
					<QTY>
						<QTY01>
							<QTY0101 decode="Cumulative quantity, actual estimated">
								<!--6063: Quantity qualifier-->138</QTY0101>
							<QTY0102>
								<!--6060: Quantity-->15</QTY0102>
							<QTY0103>
								<!--6411: Measure unit qualifier-->PCE</QTY0103>
						</QTY01>
					</QTY>
				</GROUP_7>
			</GROUP_6>
		</GROUP_5>
		<GROUP_5>
			<DTM>
				<DTM01>
					<DTM0101 decode="Horizon period">
						<!--2005: Date/time/period qualifier-->323</DTM0101>
					<DTM0102>
						<!--2380: Date/time/period-->0212</DTM0102>
					<DTM0103 decode="YYMM">
						<!--2379: Date/time/period format qualifier-->609</DTM0103>
				</DTM01>
			</DTM>
			<GROUP_6>
				<LIN>
					<LIN01>
						<!--1082: LINE ITEM NUMBER-->1</LIN01>
					<LIN03>
						<LIN0301>
							<!--7140: Item number-->188840</LIN0301>
						<LIN0302 decode="Buyer's item number">
							<!--7143: Item number type, coded-->IN</LIN0302>
						<LIN0304 decode="Assigned by buyer or buyer's agent">
							<!--3055: Code list responsible agency, coded-->92</LIN0304>
					</LIN03>
				</LIN>
				<PIA>
					<PIA01 decode="Additional identification">
						<!--4347: PRODUCT ID. FUNCTION QUALIFIER-->1</PIA01>
					<PIA03>
						<PIA0301>
							<!--7140: Item number-->0</PIA0301>
						<PIA0302 decode="Supplier's article number">
							<!--7143: Item number type, coded-->SA</PIA0302>
						<PIA0304 decode="Assigned by seller or seller's agent">
							<!--3055: Code list responsible agency, coded-->91</PIA0304>
					</PIA03>
				</PIA>
				<GROUP_7>
					<QTY>
						<QTY01>
							<QTY0101 decode="Cumulative quantity, actual estimated">
								<!--6063: Quantity qualifier-->138</QTY0101>
							<QTY0102>
								<!--6060: Quantity-->20</QTY0102>
							<QTY0103>
								<!--6411: Measure unit qualifier-->PCE</QTY0103>
						</QTY01>
					</QTY>
				</GROUP_7>
			</GROUP_6>
			<GROUP_6>
				<LIN>
					<LIN01>
						<!--1082: LINE ITEM NUMBER-->1</LIN01>
					<LIN03>
						<LIN0301>
							<!--7140: Item number-->16880</LIN0301>
						<LIN0302 decode="Buyer's item number">
							<!--7143: Item number type, coded-->IN</LIN0302>
						<LIN0304 decode="Assigned by buyer or buyer's agent">
							<!--3055: Code list responsible agency, coded-->92</LIN0304>
					</LIN03>
				</LIN>
				<PIA>
					<PIA01 decode="Additional identification">
						<!--4347: PRODUCT ID. FUNCTION QUALIFIER-->1</PIA01>
					<PIA03>
						<PIA0301>
							<!--7140: Item number-->4088888319981</PIA0301>
						<PIA0302 decode="Supplier's article number">
							<!--7143: Item number type, coded-->SA</PIA0302>
						<PIA0304 decode="Assigned by seller or seller's agent">
							<!--3055: Code list responsible agency, coded-->91</PIA0304>
					</PIA03>
				</PIA>
				<GROUP_7>
					<QTY>
						<QTY01>
							<QTY0101 decode="Cumulative quantity, actual estimated">
								<!--6063: Quantity qualifier-->138</QTY0101>
							<QTY0102>
								<!--6060: Quantity-->25</QTY0102>
							<QTY0103>
								<!--6411: Measure unit qualifier-->PCE</QTY0103>
						</QTY01>
					</QTY>
				</GROUP_7>
			</GROUP_6>
		</GROUP_5>
	</SLSFCT>
</EDIFACT>


and I'm trying to convert it to a readable HTML table. The data in the XML is actually a sales forecast and it's structure is like that:

    SLSFCT
      +
      |
      +-+GROUP_5
         +   +
         |   +->MONTH
         |
         +-+GROUP_6
            +   +
            |   +->ARTICLE/ITEM NUMBER
            |
            +-+GROUP_7
                +
                +->EXPECTED QTY


I would like to achive an output like this:

    ITEM# JAN FEB MAY
    32815   1   6  12
    48015  10  21  89


So far I got this humble approach:

<!-- language: lang-xml -->

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/EDIFACT/SLSFCT">
		<html>
			<body>
				<table border="1">
					<tr>
						<td>Artikel</td>
						<xsl:for-each select="GROUP_5/DTM">
							<td>
								<xsl:value-of select="DTM01/DTM0102"/>
							</td>
						</xsl:for-each>
					</tr>
					<xsl:for-each select="GROUP_5/GROUP_6">
						<tr>
							<td>
								<xsl:value-of select="LIN/LIN03/LIN0301"/>
							</td>
							<xsl:for-each select="../../GROUP_5">
								<td>
									<xsl:value-of select="GROUP_6/GROUP_7/QTY/QTY01/QTY0102"/>
								</td>
							</xsl:for-each>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

  

But I'm having a hard time to get the right values from `GROUP_6/GROUP_7/QTY/QTY01/QTY0102` , it seems like it's getting always the same values. Getting the months and article numbers is working fine though, just the expected sales figures (QTY0102) are wrong.

I also played around with `position()` etc. but I can't wrap my head around this :-/

So, anyone here to point me in the right direction ? Dimitre ? ;)


XSLT - convert overly nested XML to a HTML table, how to reference elements in a loop
===

I'm receiving this xml (actually this is a converted EDI/EDIFACT message):

<!-- language: lang-xml -->

    <EDIFACT>
	<SLSFCT>
		<DTM>
			<DTM01>
				<DTM0101 decode="Date, as at">
					<!--2005: Date/time/period qualifier-->183</DTM0101>
				<DTM0102>
					<!--2380: Date/time/period-->140112</DTM0102>
				<DTM0103 decode="DDMMYY">
					<!--2379: Date/time/period format qualifier-->2</DTM0103>
			</DTM01>
		</DTM>
		<GROUP_5>
			<DTM>
				<DTM01>
					<DTM0101 decode="Horizon period">
						<!--2005: Date/time/period qualifier-->323</DTM0101>
					<DTM0102>
						<!--2380: Date/time/period-->0112</DTM0102>
					<DTM0103 decode="YYMM">
						<!--2379: Date/time/period format qualifier-->609</DTM0103>
				</DTM01>
			</DTM>
			<GROUP_6>
				<LIN>
					<LIN01>
						<!--1082: LINE ITEM NUMBER-->1</LIN01>
					<LIN03>
						<LIN0301>
							<!--7140: Item number-->88840</LIN0301>
						<LIN0302 decode="Buyer's item number">
							<!--7143: Item number type, coded-->IN</LIN0302>
						<LIN0304 decode="Assigned by buyer or buyer's agent">
							<!--3055: Code list responsible agency, coded-->92</LIN0304>
					</LIN03>
				</LIN>
				<PIA>
					<PIA01 decode="Additional identification">
						<!--4347: PRODUCT ID. FUNCTION QUALIFIER-->1</PIA01>
					<PIA03>
						<PIA0301>
							<!--7140: Item number-->0</PIA0301>
						<PIA0302 decode="Supplier's article number">
							<!--7143: Item number type, coded-->SA</PIA0302>
						<PIA0304 decode="Assigned by seller or seller's agent">
							<!--3055: Code list responsible agency, coded-->91</PIA0304>
					</PIA03>
				</PIA>
				<GROUP_7>
					<QTY>
						<QTY01>
							<QTY0101 decode="Cumulative quantity, actual estimated">
								<!--6063: Quantity qualifier-->138</QTY0101>
							<QTY0102>
								<!--6060: Quantity-->10</QTY0102>
							<QTY0103>
								<!--6411: Measure unit qualifier-->PCE</QTY0103>
						</QTY01>
					</QTY>
				</GROUP_7>
			</GROUP_6>
			<GROUP_6>
				<LIN>
					<LIN01>
						<!--1082: LINE ITEM NUMBER-->1</LIN01>
					<LIN03>
						<LIN0301>
							<!--7140: Item number-->884530</LIN0301>
						<LIN0302 decode="Buyer's item number">
							<!--7143: Item number type, coded-->IN</LIN0302>
						<LIN0304 decode="Assigned by buyer or buyer's agent">
							<!--3055: Code list responsible agency, coded-->92</LIN0304>
					</LIN03>
				</LIN>
				<PIA>
					<PIA01 decode="Additional identification">
						<!--4347: PRODUCT ID. FUNCTION QUALIFIER-->1</PIA01>
					<PIA03>
						<PIA0301>
							<!--7140: Item number-->8888774319981</PIA0301>
						<PIA0302 decode="Supplier's article number">
							<!--7143: Item number type, coded-->SA</PIA0302>
						<PIA0304 decode="Assigned by seller or seller's agent">
							<!--3055: Code list responsible agency, coded-->91</PIA0304>
					</PIA03>
				</PIA>
				<GROUP_7>
					<QTY>
						<QTY01>
							<QTY0101 decode="Cumulative quantity, actual estimated">
								<!--6063: Quantity qualifier-->138</QTY0101>
							<QTY0102>
								<!--6060: Quantity-->15</QTY0102>
							<QTY0103>
								<!--6411: Measure unit qualifier-->PCE</QTY0103>
						</QTY01>
					</QTY>
				</GROUP_7>
			</GROUP_6>
		</GROUP_5>
		<GROUP_5>
			<DTM>
				<DTM01>
					<DTM0101 decode="Horizon period">
						<!--2005: Date/time/period qualifier-->323</DTM0101>
					<DTM0102>
						<!--2380: Date/time/period-->0212</DTM0102>
					<DTM0103 decode="YYMM">
						<!--2379: Date/time/period format qualifier-->609</DTM0103>
				</DTM01>
			</DTM>
			<GROUP_6>
				<LIN>
					<LIN01>
						<!--1082: LINE ITEM NUMBER-->1</LIN01>
					<LIN03>
						<LIN0301>
							<!--7140: Item number-->188840</LIN0301>
						<LIN0302 decode="Buyer's item number">
							<!--7143: Item number type, coded-->IN</LIN0302>
						<LIN0304 decode="Assigned by buyer or buyer's agent">
							<!--3055: Code list responsible agency, coded-->92</LIN0304>
					</LIN03>
				</LIN>
				<PIA>
					<PIA01 decode="Additional identification">
						<!--4347: PRODUCT ID. FUNCTION QUALIFIER-->1</PIA01>
					<PIA03>
						<PIA0301>
							<!--7140: Item number-->0</PIA0301>
						<PIA0302 decode="Supplier's article number">
							<!--7143: Item number type, coded-->SA</PIA0302>
						<PIA0304 decode="Assigned by seller or seller's agent">
							<!--3055: Code list responsible agency, coded-->91</PIA0304>
					</PIA03>
				</PIA>
				<GROUP_7>
					<QTY>
						<QTY01>
							<QTY0101 decode="Cumulative quantity, actual estimated">
								<!--6063: Quantity qualifier-->138</QTY0101>
							<QTY0102>
								<!--6060: Quantity-->20</QTY0102>
							<QTY0103>
								<!--6411: Measure unit qualifier-->PCE</QTY0103>
						</QTY01>
					</QTY>
				</GROUP_7>
			</GROUP_6>
			<GROUP_6>
				<LIN>
					<LIN01>
						<!--1082: LINE ITEM NUMBER-->1</LIN01>
					<LIN03>
						<LIN0301>
							<!--7140: Item number-->16880</LIN0301>
						<LIN0302 decode="Buyer's item number">
							<!--7143: Item number type, coded-->IN</LIN0302>
						<LIN0304 decode="Assigned by buyer or buyer's agent">
							<!--3055: Code list responsible agency, coded-->92</LIN0304>
					</LIN03>
				</LIN>
				<PIA>
					<PIA01 decode="Additional identification">
						<!--4347: PRODUCT ID. FUNCTION QUALIFIER-->1</PIA01>
					<PIA03>
						<PIA0301>
							<!--7140: Item number-->4088888319981</PIA0301>
						<PIA0302 decode="Supplier's article number">
							<!--7143: Item number type, coded-->SA</PIA0302>
						<PIA0304 decode="Assigned by seller or seller's agent">
							<!--3055: Code list responsible agency, coded-->91</PIA0304>
					</PIA03>
				</PIA>
				<GROUP_7>
					<QTY>
						<QTY01>
							<QTY0101 decode="Cumulative quantity, actual estimated">
								<!--6063: Quantity qualifier-->138</QTY0101>
							<QTY0102>
								<!--6060: Quantity-->25</QTY0102>
							<QTY0103>
								<!--6411: Measure unit qualifier-->PCE</QTY0103>
						</QTY01>
					</QTY>
				</GROUP_7>
			</GROUP_6>
		</GROUP_5>
	</SLSFCT>
</EDIFACT>


and I'm trying to convert it to a readable HTML table. The data in the XML is actually a sales forecast and it's structure is like that:

    SLSFCT
      +
      |
      +-+GROUP_5
         +   +
         |   +->MONTH
         |
         +-+GROUP_6
            +   +
            |   +->ARTICLE/ITEM NUMBER
            |
            +-+GROUP_7
                +
                +->EXPECTED QTY


I would like to achive an output like this:

    ITEM# JAN FEB MAY
    32815   1   6  12
    48015  10  21  89


So far I got this humble approach:

<!-- language: lang-xml -->

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" encoding="UTF-8" indent="yes"/>
	<xsl:template match="/EDIFACT/SLSFCT">
		<html>
			<body>
				<table border="1">
					<tr>
						<td>Artikel</td>
						<xsl:for-each select="GROUP_5/DTM">
							<td>
								<xsl:value-of select="DTM01/DTM0102"/>
							</td>
						</xsl:for-each>
					</tr>
					<xsl:for-each select="GROUP_5/GROUP_6">
						<tr>
							<td>
								<xsl:value-of select="LIN/LIN03/LIN0301"/>
							</td>
							<xsl:for-each select="../../GROUP_5">
								<td>
									<xsl:value-of select="GROUP_6/GROUP_7/QTY/QTY01/QTY0102"/>
								</td>
							</xsl:for-each>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

  

But I'm having a hard time to get the right values from `GROUP_6/GROUP_7/QTY/QTY01/QTY0102` , it seems like it's getting always the same values. Getting the months and article numbers is working fine though, just the expected sales figures (QTY0102) are wrong.

I also played around with `position()` etc. but I can't wrap my head around this :-/

So, anyone here to point me in the right direction ? Dimitre ? ;)

