Re: [xsl] How to implement common functionality

Subject: Re: [xsl] How to implement common functionality
From: "cutlass" <cutlass@xxxxxxxxxxx>
Date: Thu, 26 Jul 2001 14:52:10 +0100
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" />

here is the named template you are calling;

<xsl:template name="converttodecimal">
 <xsl:param name="amount" select="''" />
select="format-number((number(substring($amount,2)))div 100, '00.00')"/>

CSS file is for presentation details only, though i am not an expert.

here is something more complex ( taken from ), 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: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:when test="$str-length >= $pad-length">
  <xsl:value-of select="substring($string, 1, $pad-length)" />
<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 test="$alignment = 'right'">
  <xsl:value-of select="substring($padding, 1, $pad-length - $str-length)"
  <xsl:value-of select="$string" />
 <xsl:value-of select="$string" />
  <xsl:value-of select="substring($padding, $str-length + 1)" />

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@xxxxxxx>
To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx>
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
> 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,
> 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:

 XSL-List info and archive:

Current Thread