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

RE: text output and space padding

Subject: RE: text output and space padding
From: "Ben Robb" <b.robb@xxxxxxxxxx>
Date: Wed, 30 May 2001 17:02:23 +0100
xsl space pad
Yes - this is perfectly doable in XSLT... try something along the lines
of:

<xsl:template match="*">
	<xsl:value-of select=".">
	<xsl:call-template name="padMe">
		<xsl:with-param name="padTo">30</xsl:with-param>
		<xsl:with-param name="i"><xsl:value-of
select="string-length(.)"/></xsl:with-param>
	</xsl:call-template>
</xsl:template>

<xsl:template name="padMe">
	<xsl:parameter name="padTo"/>
	<xsl:parameter name="i"/>

	<!-- pad 1 space here (can't remember the correct ascii code,
off hand... -->

	<!-- now call the template again, recursively, if we are still
less than the pad value... -->
	<xsl:if test="$padMe > $i">
		<xsl:call-template name="padMe">
			<xsl:with-param name="padTo"><xsl:value-of
select="$padTo"/></xsl:with-param>
			<xsl:with-param name="i"><xsl:value-of
select="$i + 1"/></xsl:with-param>
		<xsl:call-template>
	</xsl:if>
</xsl:template>


this is equivalent to saying:

for (i, i < padMe, i++), and starting the loop at the length of the
string, add a padding space.

Ben



> -----Original Message-----
> From: angie.tong@xxxxxxxxxxxxxx [mailto:angie.tong@xxxxxxxxxxxxxx]
> Sent: 30 May 2001 16:34
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  text output and space padding
> 
> 
> I'm new to XML and XSL technologies so please give me a hand 
> here.  I have
> been researching and reading references on XSL and couldn't 
> find a way to
> do this.  I need to read an XML file and generate a flat file 
> with fixed
> length fields for mainframe.  So that means I need to write 
> data padded
> with space if the data does not fill up to the required length.  So
> something like this:
> 
>                COMPANY A                COMPANY B             
>        20000
> 
> will need to be generated from an XML file for example:
> 
> <policies>
>   <sender_info>COMPANY A</sender_info>
>   <carrier_info>COMPANY B</carrier_info>
>   <amount>200.00</amount>
> </policies>
> 
> The trick here is that the trailing space after each field might be
> different depending on the length of the data itself.  I thought about
> writing a "function" to output spaces depending on the 
> parameter input.
> But then I will need to do a for loop with index like in C:
> for (i=0;i<30;i++)
> which I know it cannot be done in XSL.  Any ideas?
> 
> Angie
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 

 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.