Jump to content

Adding Whitespace


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...