<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="text" indent="no" omit-xml-declaration="yes" />

	<xsl:variable name="maxLineLength">69</xsl:variable>

	<xsl:variable name="newline">
		<!-- Hex 10 is a line feed, and hex 13 is a carriage return -->
		<xsl:value-of select="'&#13;'" />
	</xsl:variable>
	<xsl:variable name="padding">
		<xsl:value-of select="'                                                                       '" />
	</xsl:variable>
	<xsl:variable name="divider">
		<xsl:value-of select="'-----------------------------------------------------------------------'" />
	</xsl:variable>
	<xsl:variable name="dasheddivider">
		<xsl:value-of select="'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'" />
	</xsl:variable>
	<xsl:variable name="doublequote">
		<xsl:value-of select="'&quot;'" />
	</xsl:variable>
	<xsl:variable name="asterisk">
		<xsl:value-of select="'***********************************************************************'" />
	</xsl:variable>
	<xsl:variable name="separator">
		<xsl:value-of select="'|'" />
	</xsl:variable>


	<!-- Remove all whitespace from the source XML so that it is not echoed into the new report -->
	<xsl:strip-space elements="//*" />

	<!-- set variables for the report BRAND and INVENTORYGROUP for convenience -->
	<xsl:variable name="brand">
		<xsl:value-of select="/AUTOGEN/ANNOUNCEMENT/BRAND" />
	</xsl:variable>
	
			
	<xsl:variable name="inventoryGroup">
		<xsl:value-of select="/AUTOGEN/ANNOUNCEMENT/INVENTORYGROUP" />
	</xsl:variable>


	<!-- set brand name (this is how it appears in the reports )according to the AutoGen specification (section 1.0.2) -->
	
	<xsl:variable name="brandName">
		<xsl:choose>
			<xsl:when test="/AUTOGEN/ANNOUNCEMENT/ALTBRAND">
					<xsl:value-of select="/AUTOGEN/ANNOUNCEMENT/ALTBRAND" />
			</xsl:when>
			<xsl:when test="$brand = 'pSeries'">
				<xsl:choose>
					<xsl:when test="$inventoryGroup = 'pSeries'">
						<xsl:value-of select="string('IBM System p ')" />
					</xsl:when>
					<xsl:when test="$inventoryGroup = 'eServer'">
						<xsl:value-of select="string('IBM System p ')" />
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="'unknown BRAND '" />
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="$brand = 'TotalStorage'">
					<xsl:value-of select="string('IBM System Storage ')" />
			</xsl:when>
			<xsl:when test="$brand = 'xSeries'">
					<xsl:value-of select="string('xSeries ')" />
			</xsl:when>
			<xsl:when test="$brand = 'iSeries'">
					<xsl:value-of select="string('IBM System i ')" />
			</xsl:when>
			<xsl:when test="$brand = 'zSeries'">
					<xsl:value-of select="string('IBM S/390 or zSeries ')" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="'unknown BRAND '" />
			</xsl:otherwise>
		</xsl:choose>
	
	</xsl:variable>
	
	<xsl:variable name="format1Footer">
		<xsl:text>:exmp.</xsl:text>
		<xsl:value-of select="$newline" />
		<xsl:value-of select="$newline" />
	</xsl:variable>

	<!-- begin processing of the XML data -->
	<xsl:template match="/">
		<xsl:apply-templates select="AUTOGEN" />

	</xsl:template>
	<xsl:template match="AUTOGEN">
		<xsl:call-template name="AddAnnouncementHeader" />
		<xsl:apply-templates select="ANNOUNCEMENT" />
		<xsl:call-template name="AddAnnouncementFooter" />
	</xsl:template>

	<!-- This should be redefined for each report 
		<xsl:template name="AddAnnouncementHeader" />
	-->

	<!-- build the report footer 
		<xsl:template name="AddAnnouncementFooter"/>
	-->


	<!-- build the report -->
	<xsl:template match="ANNOUNCEMENT">
		<!-- process each subsection of data if present -->
		<xsl:apply-templates select="NEW_MODELS" />
		<xsl:apply-templates select="MODEL_CONVERSIONS" />
		<xsl:apply-templates select="WITHDRAWING_MODELS" />
		<xsl:apply-templates select="WITHDRAWING_MODEL_CONVERSIONS" />		<xsl:apply-templates select="NEW_FEATURES" />
		<xsl:apply-templates select="WITHDRAWING_FEATURES" />
		<xsl:apply-templates select="FEATURE_CONVERSIONS" />
		<xsl:apply-templates select="WITHDRAWING_FEATURE_CONVERSIONS" />
		<xsl:apply-templates select="RELATED_FEATURES" />
	</xsl:template>

	<xsl:template match="NEW_MODELS" />
	<xsl:template match="MODEL_CONVERSIONS" />
	<xsl:template match="WITHDRAWING_MODELS" />
	<xsl:template match="WITHDRAWING_MODEL_CONVERSIONS" />
	<xsl:template match="NEW_FEATURES" />
	<xsl:template match="FEATURE_CONVERSIONS" />
	<xsl:template match="WITHDRAWING_FEATURES" />
	<xsl:template match="WITHDRAWING_FEATURE_CONVERSIONS" />
	<xsl:template match="RELATED_FEATURES" />

	<!-- build the section header sentence -->
	<xsl:template name="buildHeaderSentence">
		<xsl:param name="headerSentence" />
		<xsl:value-of select="concat($headerSentence, $brandName)" />
	</xsl:template>
	

	<!-- format the CSU value into the appropriate 3 character length value -->
	<!--
		‘Yes’ if INSTALL = ‘CIF’ 
		‘N/A’ if INSTALL = ‘N/A’ 
		‘N/A’ if INSTALL = ‘Does not apply’
		‘No’ if INSTALL = ‘CE’
		‘No’ if INSTALL = ‘No’
		blank if INSTALL = blank
		blank if INSTALL = null
	-->
	<xsl:template name="formatCSU">
		<xsl:param name="csu" />
		<xsl:param name="csuLength" />
		<xsl:choose>
			<xsl:when test="$csu = 'CIF' or $csu = 'Yes'">
				<xsl:value-of select="concat(substring(concat('Yes', $padding),1,$csuLength), ' ')" />
			</xsl:when>
			<xsl:when test="$csu = 'N/A' or $csu = 'Does not apply'">
				<xsl:value-of select="concat(substring(concat('N/A', $padding),1,$csuLength), ' ')" />
			</xsl:when>
			<xsl:when test="$csu = 'CE' or $csu = 'No'">
				<xsl:value-of select="concat(substring(concat('No', $padding),1,$csuLength), ' ')" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat(substring(concat(' ', $padding),1,$csuLength), ' ')" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- format the ReturnParts value into the appropriate 3 character length value -->
	<!--
		‘Yes’, If RETURNEDPARTS = Yes
		‘Yes’, if RETURNEDPARTS = Feature conversion only 
		‘No’,  If RETURNEDPARTS = No
		‘No, If RETURNEDPARTS = Does not apply
		Blank, if RETURNEDPARTS  = blank or NULL.
	-->
	<xsl:template name="formatReturnParts">
		<xsl:param name="returnParts" />
		<xsl:param name="returnPartsLength" />
		<xsl:choose>
			<xsl:when test="$returnParts = 'Feature conversion only' or $returnParts = 'Yes'">
				<xsl:value-of select="substring(concat('Yes', $padding),1,$returnPartsLength)" />
			</xsl:when>
			<xsl:when test="$returnParts = 'No' or $returnParts = 'Does not apply'">
				<xsl:value-of select="substring(concat('No', $padding),1,$returnPartsLength)" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="substring(concat(' ', $padding),1,$returnPartsLength)" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- format the MES value into the appropriate length value -->
	<xsl:template name="formatMES">
		<xsl:param name="mes" />
		<xsl:param name="mesLength" />
		<xsl:choose>
			<xsl:when test="$mes = 'Supported'">
				<xsl:value-of select="concat(substring(concat('Support', $padding),1,$mesLength), ' ')" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="concat(substring(concat($mes, $padding),1,$mesLength), ' ')" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>



	<!-- recursive section of splitString... don't call directly -->
	<xsl:template name="firstString">
		<xsl:param name="string" />
		<xsl:param name="length" />
		<xsl:param name="currentpos" />
		<xsl:param name="prefix" />
		<xsl:param name="hangingPrefix" />
		<xsl:param name="suffix" />
		<xsl:param name="hangingSuffix" />
		<xsl:param name="padding" />

		<xsl:choose>
			<xsl:when test="substring($string, $currentpos, 1) = ' '">
				<xsl:value-of select="substring($string, 1, $currentpos - 1)" />
				<xsl:value-of select="$suffix" />
				<xsl:value-of select="$newline" />

				<xsl:call-template name="splitString">
					<xsl:with-param name="string" select="substring($string, $currentpos + 1)" />
					<xsl:with-param name="length" select="$length" />
					<xsl:with-param name="prefix" select="$hangingPrefix" />
					<xsl:with-param name="hangingPrefix" select="$hangingPrefix" />
					<xsl:with-param name="suffix" select="$hangingSuffix" />
					<xsl:with-param name="hangingSuffix" select="$hangingSuffix" />
					<xsl:with-param name="padding" select="$padding" />
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="substring($string, $currentpos, 1) = '/'">
				<xsl:value-of select="substring($string, 1, $currentpos)" />
				<xsl:value-of select="$suffix" />
				<xsl:value-of select="$newline" />

				<xsl:call-template name="splitString">
					<xsl:with-param name="string" select="substring($string, $currentpos + 1)" />
					<xsl:with-param name="length" select="$length" />
					<xsl:with-param name="prefix" select="$hangingPrefix" />
					<xsl:with-param name="hangingPrefix" select="$hangingPrefix" />
					<xsl:with-param name="suffix" select="$hangingSuffix" />
					<xsl:with-param name="hangingSuffix" select="$hangingSuffix" />
					<xsl:with-param name="padding" select="$padding" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="firstString">
					<xsl:with-param name="string" select="$string" />
					<xsl:with-param name="length" select="$length" />
					<xsl:with-param name="currentpos" select="$currentpos - 1" />
					<xsl:with-param name="prefix" select="$prefix" />
					<xsl:with-param name="hangingPrefix" select="$hangingPrefix" />
					<xsl:with-param name="suffix" select="$suffix" />
					<xsl:with-param name="hangingSuffix" select="$hangingSuffix" />
					<xsl:with-param name="padding" select="$padding" />
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- split a string to a specified size.
		Note: there is no newline at the end of the last line to allow additions to the end of the line
		
		string:	string to split
		length: max length string can be per line
		prefix: optional string to prepend to the first line
		hangingPrefix:  optional string to prepend subsequent lines with
		suffix: optional string to append to the end of the first line
		hangingSuffix:  optional string to append to subsequent lines
		padding: optional string to pad the last line of a splt string with to allow extra text to be added after it
	-->
	<xsl:template name="splitString">
		<xsl:param name="string" />
		<xsl:param name="length" select="$maxLineLength" />
		<xsl:param name="prefix" />
		<xsl:param name="hangingPrefix" select="$prefix" />
		<xsl:param name="suffix" />
		<xsl:param name="hangingSuffix" select="$suffix" />
		<xsl:param name="padding" />
		
		<!-- remove extra whitespace -->
		<xsl:variable name="norm_string" select="normalize-space($string)" />

		<xsl:choose>
			<xsl:when test="(string-length($prefix) +
		  				   string-length($norm_string) + 
		  				   string-length($suffix)) &gt; $length">
				<xsl:variable name="currentpos" select="$length - string-length($suffix)" />
				<xsl:choose>
					<xsl:when test="contains(substring($norm_string, 1, $currentpos), ' ') or
									contains(substring($norm_string, 1, $currentpos), '/')">
						<xsl:call-template name="firstString">
							<xsl:with-param name="string" select="concat($prefix, $norm_string)" />
							<xsl:with-param name="length" select="$length" />
							<xsl:with-param name="currentpos" select="$currentpos" />
							<xsl:with-param name="prefix" select="$prefix" />
							<xsl:with-param name="hangingPrefix" select="$hangingPrefix" />
							<xsl:with-param name="suffix" select="$suffix" />
							<xsl:with-param name="hangingSuffix" select="$hangingSuffix" />
							<xsl:with-param name="padding" select="$padding" />
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<!-- no line split character within maximum line length -->
						<xsl:value-of select="$prefix" />
						<xsl:value-of select="substring($norm_string, 1, $currentpos - string-length($prefix))" />
						<xsl:value-of select="$suffix" />
						<xsl:value-of select="$newline" />

						<xsl:call-template name="splitString">
							<xsl:with-param name="string" select="substring($norm_string, $currentpos + 1 - string-length($prefix))" />
							<xsl:with-param name="length" select="$length" />
							<xsl:with-param name="prefix" select="$hangingPrefix" />
							<xsl:with-param name="hangingPrefix" select="$hangingPrefix" />
							<xsl:with-param name="suffix" select="$hangingSuffix" />
							<xsl:with-param name="hangingSuffix" select="$hangingSuffix" />
							<xsl:with-param name="padding" select="$padding" />
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>

			<!--  less than $length chars left, just write them -->
			<xsl:otherwise>
				<xsl:value-of select="$prefix" />
				<xsl:value-of select="$norm_string" />
				<xsl:value-of select="$suffix" />
				<xsl:value-of select="substring($padding, 1, ($length - string-length($prefix) - string-length($norm_string) - string-length($suffix))) " />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- sort list by the value of its current node -->
	<xsl:template name="sortList">
		<xsl:param name="list" />
		<xsl:for-each select="$list">
			<xsl:sort select="." />
		</xsl:for-each>
	</xsl:template>

	<!-- sort machtype model list (have to be passed with machtypemodel list) by the machtypeatr and modelatr -->
	<xsl:template name="sortMachTypeModelList">
		<xsl:param name="list" />
		<xsl:for-each select="$list">
			<xsl:sort select="MACHTYPEATR" />
			<xsl:sort select="MODELATR" />
		</xsl:for-each>
	</xsl:template>	

	<!-- print Geos begining line -->
	<xsl:template name="printGeosBegin">
		<xsl:param name="geos" />

		<xsl:if test="string-length($geos) &gt; 0">
			<xsl:text>:p.:hp2.</xsl:text>
			<xsl:value-of select="$geos" />
			<xsl:text>---&gt;:ehp2.</xsl:text>
			<xsl:value-of select="$newline" />
			<xsl:text>.br</xsl:text>
			<xsl:value-of select="$newline" />

		</xsl:if>
	</xsl:template>

	<!-- print Geos ending line  -->
	<xsl:template name="printGeosEnd">
		<xsl:param name="geos" />

		<xsl:if test="string-length($geos) &gt; 0">
			<xsl:text>.br;:hp2.&lt;---</xsl:text>
			<xsl:value-of select="$geos" />
			<xsl:text>:ehp2.</xsl:text>
			<xsl:value-of select="$newline" />

		</xsl:if>
	</xsl:template>

	<!-- print editor note  -->
	<xsl:template name="printEditorNote">
		<xsl:param name="editornote" />

		<xsl:if test="string-length($editornote) &gt; 0">
			<xsl:call-template name="splitString">
				<xsl:with-param name="string" select="$editornote" />
				<xsl:with-param name="length" select="$maxLineLength" />
				<xsl:with-param name="prefix" select="':hp2.'" />
				<xsl:with-param name="suffix" select="':ehp2.'" />
			</xsl:call-template>
			<xsl:value-of select="$newline" />
		</xsl:if>

	</xsl:template>

	<!-- print line containing Bookmaster tags  -->
	<xsl:template name="printLineWithBookmasterTags">
		<xsl:param name="string" />
		<xsl:variable name="commentTag" select="'.*'" />

		<xsl:choose>
			<!-- does line start with Bookmaster comment tag '.*' -->
			<xsl:when test="starts-with($string, $commentTag)" >
				<xsl:call-template name="splitString">
					<xsl:with-param name="string" select="substring($string, 1 + string-length($commentTag))" />
					<xsl:with-param name="prefix" select="$commentTag" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="splitString">
					<xsl:with-param name="string" select="$string" />
				</xsl:call-template>
			</xsl:otherwise>
		</xsl:choose>

		<xsl:value-of select="$newline" />
	</xsl:template>

	<!-- build a list of unique model types for the header sentence -->
	<xsl:template name="buildModelTypeList">
		<xsl:param name="uniquemachtypes" />
		<!-- Select each unique MACHTYPEATR and sort them, and add them to the header sentence -->
		<xsl:for-each select="$uniquemachtypes">
			<xsl:sort select="." />
			<xsl:choose>
				<xsl:when test="position() != last()">
					<xsl:value-of select="concat(., ', ')" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="." />
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
		<xsl:value-of select="' machine type:'" />
	</xsl:template>

	<!-- build a list of unique model types for the header sentence -->
	<xsl:template name="buildPrevModelTypeList">
		<xsl:param name="uniquemachtypes" />
		<!-- Select each unique MACHTYPEATR and sort them, and add them to the header sentence -->
		<xsl:for-each select="$uniquemachtypes">
			<xsl:sort select="." />
			<!-- test not working yet 
				<xsl:if test="//MACHTYPMODEL[PRODSTRUCT/HWFEATURE/@prevAnnounced='false']/MACHTYPEATR = ."> -->
			<xsl:choose>
				<xsl:when test="position() != last()">
					<xsl:value-of select="concat(., ', ')" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="." />
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
		<xsl:value-of select="' machine type:'" />
	</xsl:template>

	<!-- build a list of unique model types for the header sentence -->
	<!-- NOTE: key MACHTYPEMODEL-by-MACHTYPEATR must be pre-defined -->
	<xsl:template name="buildFeatureModelTypeList">
		<xsl:param name="uniquemachtypes" />
		<!-- Select each unique MACHTYPEATR and sort them, and add them to the header sentence -->
		<xsl:for-each select="$uniquemachtypes">
			<xsl:sort select="." />
			<xsl:if test="//HWFEATURE[@prevAnnounced='false']/PRODSTRUCT/MACHTYPEMODEL/MACHTYPEATR = .">
				<xsl:choose>
					<xsl:when test="position() != last()">
						<xsl:value-of select="concat(., ', ')" />
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="." />
					</xsl:otherwise>
				</xsl:choose>
			</xsl:if>
		</xsl:for-each>
		<xsl:value-of select="' machine type:'" />
	</xsl:template>

	<!-- build a list of unique model types for the header sentence -->
	<!-- NOTE: key MACHTYPEMODEL-by-MACHTYPEATR must be pre-defined -->
	<xsl:template name="buildPrevFeatureModelTypeList">
		<xsl:param name="uniquemachtypes" />
		<!-- Select each unique MACHTYPEATR and sort them, and add them to the header sentence -->
		<xsl:for-each select="$uniquemachtypes">
			<xsl:sort select="." />
			<xsl:if test="//HWFEATURE[@prevAnnounced='true']/PRODSTRUCT/MACHTYPEMODEL/MACHTYPEATR = .">
				<xsl:choose>
					<xsl:when test="position() != last()">
						<xsl:value-of select="concat(., ', ')" />
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="." />
					</xsl:otherwise>
				</xsl:choose>
			</xsl:if>
		</xsl:for-each>
		<xsl:value-of select="' machine type:'" />
	</xsl:template>

	<xsl:template name="lastIndexOf">
		<xsl:param name="string" />
		<xsl:param name="delimiter" />
		<xsl:param name="index" select="0" />

	  <xsl:choose>
    	<xsl:when test="contains($string, $delimiter)">
	      <xsl:call-template name="lastIndexOf">
    	    <xsl:with-param name="string" select="substring-after($string, $delimiter)" />
	        <xsl:with-param name="delimiter" select="$delimiter" />
		    <xsl:with-param name="index" select="$index + string-length(substring-before($string, $delimiter)) + 1" />
    	  </xsl:call-template>
	    </xsl:when>
    	<xsl:otherwise>
    		<xsl:value-of select="$index" />
    	</xsl:otherwise>
	  </xsl:choose>
	</xsl:template>

	<xsl:template name="lineSplitPos">
		<xsl:param name="string" />

		<xsl:variable name="blankPos">
		    <xsl:call-template name="lastIndexOf">
				<xsl:with-param name="string" select="$string" />
				<xsl:with-param name="delimiter" select="' '" />
		    </xsl:call-template>
		</xsl:variable>

		<xsl:variable name="slashPos">
		    <xsl:call-template name="lastIndexOf">
				<xsl:with-param name="string" select="$string" />
				<xsl:with-param name="delimiter" select="'/'" />
		    </xsl:call-template>
		</xsl:variable>

		<xsl:variable name="splitPos">
		  <xsl:choose>
    		<xsl:when test="$slashPos &gt; $blankPos">
    			<xsl:value-of select="$slashPos" />
		    </xsl:when>
    		<xsl:otherwise>
    			<xsl:value-of select="$blankPos" />
	    	</xsl:otherwise>
		  </xsl:choose>
		</xsl:variable>

		<xsl:choose>
			<xsl:when test="$splitPos = 0">
				<xsl:value-of select="string-length($string)" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$splitPos" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- Wrap strings in 2 columns of specified size.
		Note: there is no newline at the end of the last line to allow additions to the end of the line
		
		start1: starting position of 1st column
		width1: width of 1st column
		string1: string to wrap within 1st column
		start2: starting position of 2nd column
		width2: width of 2nd column
		string2: string to wrap within 2nd column
	-->
	<xsl:template name="wrap2Columns">
		<xsl:param name="start1" />
		<xsl:param name="width1" />
		<xsl:param name="string1" />
		<xsl:param name="start2" />
		<xsl:param name="width2" />
		<xsl:param name="string2" />
		
		<!-- remove extra whitespace -->
		<xsl:variable name="norm_string1" select="normalize-space($string1)" />
		<xsl:variable name="norm_string2" select="normalize-space($string2)" />

		<xsl:choose>
			<!-- fit strings into their columns -->
			<xsl:when test="string-length($norm_string1) &gt; $width1 or string-length($norm_string2) &gt; $width2">

				<xsl:variable name="splitPos1">
					<xsl:choose>
						<xsl:when test="string-length($norm_string1) &gt; $width1">
						    <xsl:call-template name="lineSplitPos">
								<xsl:with-param name="string" select="substring($norm_string1, 1, $width1)" />
	    					</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="string-length($norm_string1)" />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>

				<xsl:variable name="splitPos2">
					<xsl:choose>
						<xsl:when test="string-length($norm_string2) &gt; $width2">
						    <xsl:call-template name="lineSplitPos">
								<xsl:with-param name="string" select="substring($norm_string2, 1, $width2)" />
		    				</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="string-length($norm_string2)" />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>

				<xsl:value-of select="concat(
				substring($padding, 1, $start1 - 1),
				substring(concat(substring($norm_string1, 1, $splitPos1), $padding), 1, $width1),
				substring($padding, 1, $start2 - ($start1 + $width1)),
				substring(concat(substring($norm_string2, 1, $splitPos2), $padding), 1, $width2)
				) " />
				<xsl:value-of select="$newline" />

				<xsl:call-template name="wrap2Columns">
					<xsl:with-param name="start1" select="$start1" />
					<xsl:with-param name="width1" select="$width1" />
					<xsl:with-param name="string1" select="substring($norm_string1, $splitPos1 + 1)" />
					<xsl:with-param name="start2" select="$start2" />
					<xsl:with-param name="width2" select="$width2" />
					<xsl:with-param name="string2" select="substring($norm_string2, $splitPos2 + 1)" />
				</xsl:call-template>
			</xsl:when>
			<!--  both strings fit into their columns, just write them -->
			<xsl:otherwise>
				<xsl:value-of select="concat(
				substring($padding, 1, $start1 - 1),
				substring(concat($norm_string1, $padding), 1, $width1),
				substring($padding, 1, $start2 - ($start1 + $width1)),
				substring(concat($norm_string2, $padding), 1, $width2)
				) " />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>