Name

element-available()

Determines if a given element is available to the XSLT processor. This function allows you to design stylesheets that react gracefully if a particular extension element is not available to process an XML document.

Syntax

[1.0] boolean element-available($elementName as string)
[2.0] xs:boolean element-available($elementName as xs:string)

Inputs

The element’s name. The name should be qualified with a namespace; if the namespace URI is the same as the XSLT namespace URI, then the element name refers to an element defined by XSLT. Otherwise, the name refers to an extension element. If the element name has a null namespace URI, then the element-available function returns false. [2.0] If the argument cannot be converted to a valid QName, the XSLT processor raises an error.

Output

The boolean value true if the element is available; false otherwise.

Defined in

[1.0] XSLT section 15, “Fallback.”

[2.0] XSLT section 18.2, “Extension Instructions.”

Example

We’ll illustrate the element-available() function with the following XML document:

<?xml version="1.0"?>
<!-- chapterlist.xml --> <book> <title>XSLT</title> <chapter> <title>Getting Started</title> <para>If this chapter had any text, it would appear here.</para> </chapter> <chapter> <title>The Hello World Example</title> <para>If this chapter had any text, it would appear here.</para> </chapter> ... <chapter> <title>Combining XML Documents</title> <para>If this chapter had any text, it would appear here.</para> </chapter> </book> ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.