Jump to content

Adding Whitespace


mitchpau
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...