RE: Forcing String Length?

Subject: RE: Forcing String Length?
From: "Chris Bayes" <Chris@xxxxxxxxxxx>
Date: Fri, 22 Sep 2000 14:33:45 -0400 (EST)
Rebecca,
Try something like

<xsl:template match="something">

	<xsl:call-template name="padto10">
		<xsl:with-param name="string" select="text()" />
	</xsl:call-template>

</xsl:template>


<xsl:template name="padto10">
  <xsl:param name="string" />
  <xsl:variable name="spadding" select="'          '" />
  <xsl:variable name="ipadding" select="'0000000000'" />
  <xsl:if test="string-length(normalize-space(translate(., '1234567890', '
')))>0">
    <xsl:value-of select="concat($string , substring($spadding,
string-length($string)))" />
  </xsl:if>
  <xsl:if test="string-length(normalize-space(translate(., '1234567890', '
')))=0">
    <xsl:value-of select="concat($string , substring($ipadding,
string-length($string)))" />
  </xsl:if>
</xsl:template>


Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml

My question for the day is this:

Is there away to force string length? For example, my output contains a
string that must contain 10 characters but the XML source is not guaranteed
to supply that number of characters.

Is there a better, shorter way than doing a long series using <xsl:choose>,
testing string-length=10, string-length=9 etc and filling in the appropriate
number of spaces (or 0's if it's a number)

My stylesheet HUGE because I have so many places where this must be done.
It's working but I've got to find ways to trim it down.

Help!

Thanks,
Rebecca




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread