developer
developer

Reputation: 1697

Function in XSLT

I am using the following formula at a lot of places inside an xsl file.

<xsl:value-of select="format-number($Value div 1000000, '##.##')" />

Is there anyway I can create a function so I can keep the logic at one place and reuse it as per below example?

Example:

<xsl:value-of select="ConvertToMillionAndFormatNumber($Value)" />

Upvotes: 0

Views: 85

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117102

There are no custom functions in XSLT 1.0 (unless your processor happens to support them as an extension), but you can use a named template:

<xsl:template name="ConvertToMillionAndFormatNumber">
    <xsl:param name="Value" />
    <xsl:value-of select="format-number($Value div 1000000, '##.##')" />
</xsl:template>

and call it as:

<xsl:call-template name="ConvertToMillionAndFormatNumber">
    <xsl:with-param name="Value" select="your-value-here"/>
</xsl:call-template>

Upvotes: 1

Related Questions