mitchpau Posted July 22, 2009 Share Posted July 22, 2009 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 More sharing options...
aalbetski Posted July 23, 2009 Share Posted July 23, 2009 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 More sharing options...
mitchpau Posted July 24, 2009 Author Share Posted July 24, 2009 Thanks ! Link to comment Share on other sites More sharing options...
mitchpau Posted July 27, 2009 Author Share Posted July 27, 2009 Hi, one question I have about the template. How do I prevent it from adding a new line at the end?ThanksMitch Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.