Extension functions

A vendor may add more functions to the expression language. As these would not be XSLT or XPath functions, they must be defined using a different namespace. For example, a vendor may add a function that is able to reverse the characters in a text string, called reverse():

   <reverse>abcdefghijklmnopqrstuvwxyz</reverse>


<xsl:template match="reverse">
  <P><xsl:value-of select="acme:reverse(.)"/></P>
</xsl:template>


   <P>zyxwvutsrqponmlkjihgfedcba</P>

New functions must have a prefix, or they will be assumed to be extensions to those defined by XPath or XSLT (in a later version of these standards).

While an XSLT processor that does not understand the new function must raise an error if an attempt is made to use it, the processor will not raise the error merely because it is present in the stylesheet. This allows the stylesheet to contain such functions, but also to include a mechanism to avoid them when they will not be understood. The function-available() function returns 'false' if the function name passed to it is not supported. It can be used in If and Choose elements to avoid calling unknown functions, and to take some other 'fallback' action instead:

<xsl:template match="reverse">
  <P>
    <xsl:if test="function-available (acme:reverse)">
      <xsl:value-of select="acme:reverse(.)"/>
    </xsl:if>
    <xsl:if test="not(function-available(acme:reverse))">
      <xsl:value-of select="."/> (NORMALLY REVERSED)
    </xsl:if>
  </P>
</xsl:template>

When the function returns 'false', the following would be output:

<P>abcdefghijklmnopqrstuvwxyz (NORMALLY REVERSED)</P>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset