This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How to implement common functionality
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] How to implement common functionality
- From: "cutlass" <cutlass at secure0 dot com>
- Date: Thu, 26 Jul 2001 14:52:10 +0100
- References: <53FEA05B1DD1D411AF8C0060B0679CE136BA30@msgmro539nts.fmr.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
the first simplest step is to create a named template
this is how u would call the function;
<xsl:call-template name="converttodecimal">
<xsl:with-param name="amount" select="@DOLLARAMT" />
</xsl:call-template>
here is the named template you are calling;
<xsl:template name="converttodecimal">
<xsl:param name="amount" select="''" />
<xsl:value-of
select="format-number((number(substring($amount,2)))div 100, '00.00')"/>
</xsl:template>
CSS file is for presentation details only, though i am not an expert.
here is something more complex ( taken from
http://www.exslt.org/str/functions/align/index.html ), note the str: prefix,
to use this particular example you will have to declare a namespace str: i
would suggest taking a look at the above exslt link,
<xsl:call-template name="str:align">
<xsl:with-param name="string" select="string" />
<xsl:with-param name="padding" select="string" />
<xsl:with-param name="alignment" select="string" />?
</xsl:call-template>
<xsl:template name="str:align">
<xsl:param name="string" select="''" />
<xsl:param name="padding" select="''" />
<xsl:param name="alignment" select="'left'" />
<xsl:variable name="str-length" select="string-length($string)" />
<xsl:variable name="pad-length" select="string-length($padding)" />
<xsl:choose>
<xsl:when test="$str-length >= $pad-length">
<xsl:value-of select="substring($string, 1, $pad-length)" />
</xsl:when>
<xsl:when test="$alignment = 'center'">
<xsl:variable name="half-remainder" select="floor(($pad-length -
$str-length) div 2)" />
<xsl:value-of select="substring($padding, 1, $half-remainder)" />
<xsl:value-of select="$string" />
<xsl:value-of select="substring($padding, $str-length + $half-remainder +
1)" />
</xsl:when>
<xsl:when test="$alignment = 'right'">
<xsl:value-of select="substring($padding, 1, $pad-length - $str-length)"
/>
<xsl:value-of select="$string" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
<xsl:value-of select="substring($padding, $str-length + 1)" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
once u have mastered this u will may want to bind these functions to
specific namespaces, etc, anyway this is a good first step
cheers, jim fuller
----- Original Message -----
From: "Haque, Suraiya" <Suraiya.Haque@FMR.COM>
To: <XSL-List@lists.mulberrytech.com>
Sent: Thursday, July 26, 2001 2:35 PM
Subject: [xsl] How to implement common functionality
> I have to do some text formatting in multiple XSL files using the
> same format. I would like to define this once in a central file and reuse
it
> in the XSL files. Right now I have the formatting implemented for each
> field.
>
> In my XML, 10.00 is specified as +000000001000
> and I format it to 10.00 by using
>
> <xsl:value-of
> select="format-number((number(substring(@DOLLARAMT,2)))div 100,
'00.00')"/>
>
> I would like to define the formatting command in a central place so
> that I can do something like this:
>
> <xsl:value-of select="convertToDecimal(@DOLLARAMT)"/>
>
> Is there a way to do this? Can I do this in a css file?
>
> Thanks,
> Suraiya
>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list