<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>

	<xsl:key name="Qualifier" match="LIST/LIST_ST/REF" use="concat(count(../following-sibling::LIST_ST), Qualifier)"/>

	<xsl:template match="/">
		<HTML>
			<HEAD>
				<TITLE>850</TITLE>
			</HEAD>

			<xsl:for-each select="LIST/LIST_ST">
				<BODY>
					<H3>Purchase Order Details</H3>
					<H2><xsl:value-of select="concat('Purchase Order ', position(), '-', BEG/PONumber)"/></H2>

					<table border="2" cellpadding="3" rules="all" bgcolor="#D8C454">
						<TH>Qualifier</TH>
						<TH>Code</TH>
						<TH>Text</TH>

						<xsl:for-each select="REF[generate-id(.) = generate-id(
							key('Qualifier', concat(count(../following-sibling::LIST_ST), Qualifier))[1]) ]">
							<TR>
								<TD><xsl:value-of select="Qualifier"/></TD>
								<TD><xsl:value-of select="Code"/></TD>
								<TD>
									<xsl:variable name="group" select="key('Qualifier', concat(count(../following-sibling::LIST_ST), Qualifier))"/>
									<xsl:variable name="v1">
										<xsl:for-each select="$group/Text">
											<xsl:value-of select="."/>
										</xsl:for-each>
									</xsl:variable>
									<xsl:value-of select="$v1"/>
								</TD>
							</TR>
						</xsl:for-each>
					</table>
				</BODY>
			</xsl:for-each>
		</HTML>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2009. Progress Software Corporation. All rights reserved.

<metaInformation>
	<scenarios>
		<scenario default="yes" name="po.xml" userelativepaths="yes" externalpreview="no" url="po.xml" htmlbaseurl="" outputurl="" processortype="saxon8" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline=""
		          additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator="">
			<advancedProp name="sInitialMode" value=""/>
			<advancedProp name="bXsltOneIsOkay" value="true"/>
			<advancedProp name="bSchemaAware" value="true"/>
			<advancedProp name="bXml11" value="false"/>
			<advancedProp name="iValidation" value="0"/>
			<advancedProp name="bExtensions" value="true"/>
			<advancedProp name="iWhitespace" value="0"/>
			<advancedProp name="sInitialTemplate" value=""/>
			<advancedProp name="bTinyTree" value="true"/>
			<advancedProp name="bWarnings" value="true"/>
			<advancedProp name="bUseDTD" value="false"/>
			<advancedProp name="iErrorHandling" value="fatal"/>
		</scenario>
	</scenarios>
	<MapperMetaTag>
		<MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
		<MapperBlockPosition></MapperBlockPosition>
		<TemplateContext></TemplateContext>
		<MapperFilter side="source"></MapperFilter>
	</MapperMetaTag>
</metaInformation>
-->