O'Reilly logo

XSLT, 2nd Edition by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required