<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
	<xsl:output method="text"/>
	<xsl:template match="products/product">
		<!--variables normalized input-->
		<xsl:variable name="idN" select="normalize-space(@id)"/>
		<xsl:variable name="nameN" select="normalize-space(name)"/>
		<xsl:variable name="priceN" select="normalize-space(price)"/>
		<xsl:variable name="stockN" select="normalize-space(stock)"/>
		<xsl:variable name="countryN" select="normalize-space(country)"/>
		<!--variables formated input-->
		<xsl:variable name="priceNF" select="format-number($priceN, '#,##0.00')"/>
		<!--variables extra spaces-->
		<xsl:variable name="idSpace">
			<xsl:call-template name="times">
				<xsl:with-param name="counter" select="3 - string-length($idN)"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="nameSpace">
			<xsl:call-template name="times">
				<xsl:with-param name="counter" select="8 - string-length($nameN)"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="priceSpace">
			<xsl:call-template name="times">
				<xsl:with-param name="counter" select="10 - string-length($priceNF)"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="stockSpace">
			<xsl:call-template name="times">
				<xsl:with-param name="counter" select="3 - string-length($stockN)"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="countrySpace">
			<xsl:call-template name="times">
				<xsl:with-param name="counter" select="10 - string-length($countryN)"/>
			</xsl:call-template>
		</xsl:variable>
		<!--fixed output begins here-->
		<xsl:value-of
			select="concat($idN, $idSpace, $nameSpace, $nameN, $priceSpace, $priceNF, $stockSpace, $stockN, $countrySpace, $countryN)"/>
		<xsl:text>&#xA;</xsl:text>
	</xsl:template>
	<!--template to return spaces x number of times-->
	<xsl:template name="times">
		<xsl:param name="counter"/>
		<xsl:if test="$counter > 0">
			<xsl:value-of select="' '"/>
			<xsl:call-template name="times">
				<xsl:with-param name="counter" select="$counter - 1"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	<!-- Version 1c -->
	<!-- 1) We have formatted the price output using decimal-format. -->
	<!-- 2) Note: We don't declare the English decimal format at the top relying on English as default. -->
	<!-- 3) We use only one value-of and one concat to create output. -->
	<!-- 4) XMLSpy's built-in processor is stripping whitespace-only text-nodes. Xsl:strip-space is not needed. -->
	<!-- 5) In Saxon we must include xsl:strip-space or delete the linefeed at the end of last template. -->
	<!-- 6) The solution above works in both Saxon and in XMLSpy's build-in processor. -->
</xsl:stylesheet>
