Jump to content

Adding Whitespace


mitchpau

Recommended Posts

Hi,I have a question regarding dreaded whitespace. I am using xsl to convert XML into flat file record structure. This requires much padding out of the values with white space to accommodate fixed length file structuresCan anyone advise on the easiest way to do this?Thanks!!Mitch

Link to comment
Share on other sites

Again, recursion can be usedTry this (Note that the CharToPad is a space, but can be anything you put in there. I used <pre> tags because they maintain whitespace in a browser where I test.

		<xsl:template match="/">			<pre>			<xsl:call-template name="PadRight">				<xsl:with-param name="TextToPad">This Must be length of 50</xsl:with-param>				<xsl:with-param name="Length">50</xsl:with-param>				<xsl:with-param name="CharToPad"><xsl:text> </xsl:text></xsl:with-param>			</xsl:call-template>			</pre>		</xsl:template>		<xsl:template name="PadRight">			<xsl:param name="TextToPad" />			<xsl:param name="Length" />			<xsl:param name="CharToPad"/>			<xsl:choose>				<xsl:when test="string-length($TextToPad) >= $Length">					<xsl:value-of select="$TextToPad" />				</xsl:when>				<xsl:otherwise>					<xsl:call-template name="PadRight">						<xsl:with-param name="TextToPad" select="concat($TextToPad,$CharToPad)"/>						<xsl:with-param name="Length" select="$Length" />						<xsl:with-param name="CharToPad" select="$CharToPad" />					</xsl:call-template>				</xsl:otherwise>			</xsl:choose>		</xsl:template>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...