[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: creating a string of repeated characters or Paddin

Subject: Re: creating a string of repeated characters or Padding
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 16 Aug 2001 17:58:50 +0100
creating string with 100 characters
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>&#xA;</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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.