0

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)" />
developer
  • 1,401
  • 4
  • 28
  • 73
  • 1
    Depending on the context you might need or not a function. For example, you could use template rules to match text nodes. As for using user defined functions, in XSLT 1.0 you need the [extension function mechanism](https://www.w3.org/TR/xslt-10/#section-Extension-Functions). There are several questions and answers for each specific XSLT processor. – Alejandro Jul 30 '19 at 13:52

1 Answers1

1

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>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51