Name
[2.0] <xsl:function>
Defines a function that can be used in XPath expressions in the stylesheet.
Category
Declaration.
Required Attribute
nameThe name of the stylesheet function.
Optional Attributes
asDefines the datatype returned by this function.
overrideDefines 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.
Content
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.”
Example
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="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sample="http://www.oreilly.com/catalog/xslt" 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, ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access