Subject: Re: [xsl] creating a string of repeated characters or Padding From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Thu, 16 Aug 2001 17:58:50 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] creating a string of repe, Lomvardias, Christop | Thread | Re: [xsl] creating a string of repe, Kurt Cagle |
Re: [xsl] Weird XSL refresh problem, Michael Beddow | Date | Re: [xsl] how do I include schema f, Choon Tan |
Month |