<?xml version="1.0"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
	<xsl:variable name="numtran">
		<xsl:value-of select="substring(translate(translate(translate(translate(substring-before(current-dateTime(), '+'),':',''),'.',''),'-',''),'T',''),4,17)"/>
	</xsl:variable>
	<xsl:template match="/">
			<xsl:apply-templates select="table/row[2]/column" mode="stores"/>
	</xsl:template>

	<xsl:template match="column" mode="stores">
		<xsl:param name="store_id" select="./@column"/>
		<xsl:if test="($store_id&gt;'1') and (string-length(.)&gt;0)">
			<xsl:variable name="A" select="./@column"/>
			<xsl:if test="../../row[3]/column[@column=$A]&gt;=0">
			<xsl:variable name="AAA" select="."/>
			<xsl:result-document method="xml" href="orders_{$AAA}_{$numtran}.xml">
				<ORDER>
						<BUYER>
							<xsl:value-of select="../../row[1]/column[2]"/>
						</BUYER>
						<DELIVERYPLACE>
							<xsl:value-of select="."/>
						</DELIVERYPLACE>
						<SENDER>
							<xsl:value-of select="../../row[1]/column[2]"/>
						</SENDER>
						<xsl:apply-templates select="../../row" mode="products">
							<xsl:with-param name="store_id" select="$store_id"/>
						</xsl:apply-templates>
				</ORDER>
			</xsl:result-document>
			</xsl:if>
		</xsl:if>
	</xsl:template>

	<xsl:template match="row" mode="products">
		<xsl:param name="store_id"/>
		<xsl:if test="(@row&gt;2) and (column[@column=$store_id]&gt;0)">
			<POSITION>
				<POSITIONNUMBER>
					<xsl:value-of select="position()-2"/>
				</POSITIONNUMBER>
				<xsl:for-each select="column">
					<xsl:if test="@column=1">
						<PRODUCT>
							<xsl:value-of select="."/>
						</PRODUCT>
					</xsl:if>
					<xsl:if test="@column=$store_id">
						<ORDEREDQUANTITY>
							<xsl:value-of select="."/>
						</ORDEREDQUANTITY>
					</xsl:if>
					<xsl:if test="@column=0">
						<CHARACTERISTIC>
							<DESCRIPTION>
								<xsl:value-of select="."/>
							</DESCRIPTION>
						</CHARACTERISTIC>
					</xsl:if>
				</xsl:for-each>
			</POSITION>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2009. Progress Software Corporation. All rights reserved.

<metaInformation>
	<scenarios>
		<scenario default="yes" name="SV_for_Megapolis_30_12_2011__12_55_06.xml" userelativepaths="yes" externalpreview="no" url="orders_12_58_39.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>
-->