[2.0] <xsl:function>

Defines a function that can be used in XPath expressions in the stylesheet.



Required Attribute


The name of the stylesheet function.

Optional Attributes


Defines the datatype returned by this function.


Defines whether this function should override another function with the same name and the same number of arguments that is provided by the processor outside the scope of the stylesheet. override="yes", the default value, means this function will be used (it overrides the other function); override="no" means the other function will be used.


Any number of <xsl:param> elements, followed by a sequence constructor. The created sequence is returned by the function.

Defined in

XSLT section 10.3, “Stylesheet Functions.”


This stylesheet uses three <xsl:function>s to return the background color, font size, and style of various HTML elements. Putting the logic into a function means we can access the function from an attribute value template. Here’s the stylesheet:

<?xml version="1.0" encoding="utf-8"?>
<!-- function.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="" xmlns:xs="" xmlns:sample="" exclude-result-prefixes="xs sample"> <xsl:output method="html" include-content-type="no"/> <xsl:variable name="colors" as="xs:string *" select="('yellow', 'white', 'blue')"/> <xsl:variable name="fontSizes" as="xs:integer *" select="(18, 24, ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.