xsl:function

Allows the creation of user-defined stylesheet function that can be called from any XPath expression within the stylesheet in which the function is defined. This instruction is supported in XSLT 2.0 only.

Format

<xsl:function name="Qname" as="sequence type" [override="yes" | "no"]>
               
function_body
               
</xsl:function>
               

            

Description

The value of the name attribute, Qname, is a qualified name and takes the form prefix :name. The prefix is required in order to avoid possible conflicts with any functions in the default function namespace. The prefix cannot refer to a reserved namespace.

The function_body contains zero or more <hyperlink>xsl:param elements that specify the formal arguments of the function. These xsl:param elements are followed by a sequence constructor that defnes the value to be returned by the function. The xsl:param elements within an xsl:function element must be empty; they cannot have a select attribute because they must be specified.

An xsl:function declaration can only appear as a top-level element in a stylesheet.

Example

Here is an example from the W3C XSLT Working Draft of a simple function that reverses the order of the words in a sentence.

<xsl:transform 
               
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
               
  xmlns:str="http://example.com/namespace"
               
  version="2.0"
               
  exclude-result-prefixes="str">
               
 
               
<xsl:function name="str:reverse" as="xs:string">
               
  <xsl:param name="sentence" as="xs:string"/>
               
  <xsl:sequence  
               
     select="if (contains($sentence, ' '))
               
             then concat(str:reverse(substring-after($sentence, ' ')),
               
                         ' ',
               
                         substring-before($sentence, ' '))
               
             else $sentence"/>
               
</xsl:function>
               
 
               
<xsl:template match="/">
               
<output>
               
  <xsl:value-of select="str:reverse('DOG BITES MAN')"/>
               
</output>
               
</xsl:template>
               
 
               
</xsl:transform>
               

            

Government Agencies That Use Stylus Studio

Government agencies all around the nation are pledging their allegiance to Stylus Studio. Come see which government agencies are using the only XML IDE by the people and for the people.

Biotechnology & Pharmaceuticals

Leading biotechnology & pharmaceuticals companies take Stylus Studio when they are feeling under the weather. Come see for yourself how Stylus Studio can be a pick me up for your biotechnology or pharmaceutical company.

XML Schema Validator, DTD Validator

Stylus Studio lets you validate XML documents using integrated XML Schema or DTD validators. Use the Stylus Studio built-in validator, or any number of supported XML parsers and XML validators like MSXML SAX and DOM, Xerces, .NET, and more!

FLWOR - An Introduction to the XQuery FLWOR Expression

An XQuery FLWOR Tutorial, covering an introduction to the main constructs of the XQuery FLWOR expression, including: For, Let, Where, Order By, and Return. Written by the W3C's Dr. Michael Kay.

Stylus Most Wanted

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.