[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] generation of flat file from XSL


Subject: RE: [xsl] generation of flat file from XSL
From: Rajendra S Rawat <rajsrawat@xxxxxxxxx>
Date: Mon, 13 Oct 2003 21:01:21 -0700 (PDT)

Try these 2 templates to get fixed width strings:

	<xsl:template name="L-pad">
		<xsl:param name="padChar"> </xsl:param>
		<xsl:param name="padVar"/>
		<xsl:param name="length"/>
		<xsl:choose>
			<xsl:when test="string-length($padVar) &lt;
$length">
				<xsl:call-template name="L-pad">
					<xsl:with-param name="padChar"
select="$padChar"/>
					<xsl:with-param name="padVar"
select="concat($padChar,$padVar)"/>
					<xsl:with-param name="length" select="$length"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of
select="substring($padVar,string-length($padVar) -	 
$length + 1)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="R-pad">
		<xsl:param name="padChar"/>
		<xsl:param name="padVar"/>
		<xsl:param name="length"/>
		<xsl:choose>
			<xsl:when test="string-length($padVar) &lt;
$length">
				<xsl:call-template name="R-pad">
					<xsl:with-param name="padChar"
select="$padChar"/>
					<xsl:with-param name="padVar"
select="concat($padVar,$padChar)"/>
					<xsl:with-param name="length" select="$length"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of
select="substring($padVar,1,$length)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>


for more details try this link:

http://www.dpawson.co.uk/xsl/sect2/padding.html



Cheers,
Raj
--- Michael Kay <mhk@xxxxxxxxx> wrote:
> > I have worked on generation of a flat file from
> xml using 
> > XSL. I have used  select:value-of for the data and
> xsl:text 
> > to put the commas in the flat file.
> > 
> > 
> > Could some body let me know if the flat file can
> be generated 
> > as  a fixed field length file and 
> > the necessary options xsl has.
> 
> It can, but you need to do more work. Write a
> template like:
> 
> <xsl:template name="pad">
> <xsl:param name="value"/>
> <xsl:param name="size"/>
> <xsl:variable name="spaces"
>  select="'                                          
>  '"/>
> <xsl:value-of select="substring(concat($value,
> $spaces), 1, $size)"/>
> </xsl:template>
> 
> Michael Kay
>    
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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



Current Thread
Keywords