Funkce

  • pomocí xsl:function lze deklarovat funkce, které pak lze přímo používat v XPathu

Příklad 10. Jednoduchá funkce a její použití – faktorial.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:f="http://example.com/funkce"
                version="2.0">

<xsl:function name="f:faktorial" as="xs:integer">
  <xsl:param name="n" as="xs:integer"/>
  
  <xsl:sequence select="if ($n > 1) then $n * f:faktorial($n - 1)
                                    else 1"/>
</xsl:function>
  
<xsl:template match="/">
  <xsl:value-of select="f:faktorial(42)"/>
</xsl:template>

</xsl:stylesheet>