ryder.dev

How to Declare a Namespace in XQuery

May 08, 2021

Namespace prefix has not been declared error

Namespaces can be a big pain. If you try to run an XQuery on something like an XSL stylesheet (where all the XSL elements are prefixed with the xsl: prefix), you might run into an error like this:

Namespace prefix 'xsl' has not been declared

Solution

The solution is as simple as declaring the namespace. Here’s an example:

declare namespace xsl = "http://www.w3.org/1999/XSL/Transform";
count(//xsl:template)