This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: creating a string of repeated characters or Padding
- To: "Lomvardias, Christopher" <clomvardias at syscom dot com>
- Subject: Re: [xsl] creating a string of repeated characters or Padding
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 16 Aug 2001 17:58:50 +0100
- CC: "'XSL-List at lists dot mulberrytech dot com'" <XSL-List at lists dot mulberrytech dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <78F894212370D511BFB500508B78799F03C622@SYSCOMEX>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Chris,
> So, I've read the exslt documentation on string padding but it's not
> exactly clear to me how I would invoke this function given the
> following excerpted xslt where I need ACTIVITY to always occupy
> positions 16-65 and MEMBER to occupy positions 66-165 in my fixed
> file output.
It sounds as though you can break down each row into three areas:
- 16 characters (presumably spaces)
- the value of ACTIVITY aligned in 50 characters (spaces)
- the value of MEMBER aligned in 100 characters (spaces)
So, first you need to output a string of 16 characters, which you can
get with the str:padding template.
<xsl:template match="ROW">
<xsl:call-template name="str:padding">
<xsl:with-param name="length" select="16" />
</xsl:call-template>
...
</xsl:template>
Then I'd set up a variable to hold the 50 character padding so that
you can make the 100 character padding fairly easily:
<xsl:template match="ROW">
<xsl:call-template name="str:padding">...</xsl:call-template>
<xsl:variable name="spaces50">
<xsl:call-template name="str:padding">
<xsl:with-param name="length" select="50" />
</xsl:call-template>
</xsl:variable>
...
</xsl:template>
Then I'd use the str:align template (from
http://www.exslt.org/str/functions/align/str.align.template.xsl) to
(left) align the values of ACTIVITY in those 50 characters:
<xsl:template match="ROW">
<xsl:call-template name="str:padding">...</xsl:call-template>
<xsl:variable name="spaces50">...</xsl:variable>
<xsl:call-template name="str:align">
<xsl:with-param name="string" select="ACTIVITY" />
<xsl:with-param name="padding" select="$spaces50" />
</xsl:call-template>
...
</xsl:template>
Then call the str:align template to pad the value of the MEMBER child
in 100 spaces:
<xsl:template match="ROW">
<xsl:call-template name="str:padding">...</xsl:call-template>
<xsl:variable name="spaces50">...</xsl:variable>
<xsl:call-template name="str:align">...</xsl:call-template>
<xsl:call-template name="str:align">
<xsl:with-param name="string" select="MEMBER" />
<xsl:with-param name="padding"
select="concat($spaces50, $spaces50)" />
</xsl:call-template>
...
</xsl:template>
Finally, of course, you need your new line:
<xsl:template match="ROW">
<xsl:call-template name="str:padding">...</xsl:call-template>
<xsl:variable name="spaces50">...</xsl:variable>
<xsl:call-template name="str:align">...</xsl:call-template>
<xsl:call-template name="str:align">...</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:template>
Of course you could split it up into separate templates if you wanted.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list