{"record":{"id":"6c62fc97701cd2ae","repo":"dianping/cat","slug":"xpst0081","errorCode":"XPST0081","errorMessage":"\"{prefix}\": can not expand prefix of lexical QName to namespace URI","messagePattern":"\"(.+?)\": can not expand prefix of lexical QName to namespace URI","errorType":"error_code","errorClass":"StaticError","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-xquery.js","lineNumber":1880,"sourceCode":"        },\n        \n        resolveQName: function(value, pos){\n            var qname = {\n                uri: '',\n                prefix: '',\n                name: ''\n            };\n            var idx;\n            if (value.substring(0, 2) === 'Q{') {\n                idx = value.indexOf('}');\n                qname.uri = value.substring(2, idx);\n                qname.name = value.substring(idx + 1);\n            } else {\n                idx = value.indexOf(':');\n                qname.prefix = value.substring(0, idx);\n                var namespace = this.getNamespaceByPrefix(qname.prefix);\n                if(!namespace && qname.prefix !== '' && ['fn', 'jn'].indexOf(qname.prefix) === -1) {\n                    throw new StaticError('XPST0081', '\"' + qname.prefix + '\": can not expand prefix of lexical QName to namespace URI', pos);\n                }\n                if(namespace) {\n                    qname.uri = namespace.uri;\n                }\n                qname.name = value.substring(idx + 1);\n            }\n            return qname;\n        },\n        \n        variables: {},\n        varRefs: {},\n        functionCalls: {},\n    \n        addVariable: function(qname, type, pos){\n            if(\n                type === 'VarDecl' && this.moduleNamespace !== '' &&\n                !(this.moduleNamespace === qname.uri || (qname.uri === '' && this.defaultFunctionNamespace === this.moduleNamespace))\n            ) {","sourceCodeStart":1862,"sourceCodeEnd":1898,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-xquery.js#L1862-L1898","documentation":"XPST0081 is the XQuery static error for a lexical QName whose prefix cannot be expanded to a namespace URI. During QName parsing, the worker splits 'prefix:local'; if getPrefixByPrefix finds no binding, the prefix is non-empty, and it is not one of the implicitly known 'fn'/'jn' prefixes, the static error is raised. Q{...}URI-qualified names never hit this path because they carry the URI inline.","triggerScenarios":"Using foo:bar(...) or foo:bar in the query body when 'declare namespace foo = ...' / a matching import is missing (or is declared after the point of use in module context). Also typos in prefixes of well-known namespaces (e.g. 'xss:...' instead of 'xs:...').","commonSituations":"Deleting an import but not its call sites; prefix typos; using a module function before importing the module; copied snippets that reference prefixes declared elsewhere; note fn and jn are hardcoded as always-available, other prefixes are not.","solutions":["Add the missing 'declare namespace prefix = \"URI\";' or 'import module namespace prefix = \"URI\";' to the prolog.","Fix the prefix typo (very common with 'xs' vs 'xss', 'local' vs 'locals').","As a robust alternative, use the URI-qualified form 'Q{http://...}name' which needs no prefix binding."],"exampleFix":"// before\nlet $v := math:sqrt(4) return $v\n(: no declare namespace math :)\n\n// after\ndeclare namespace math = \"http://www.w3.org/2005/xpath-functions/math\";\nlet $v := math:sqrt(4) return $v","handlingStrategy":"validation","validationCode":"// Verify every prefixed name used in the body has a prolog binding\nvar declared = collectDeclaredPrefixes(prolog); // ['fn','xs','m', ...]\nvar used = collectUsedPrefixes(body);\nvar unknown = used.filter(function(p) {\n  return declared.indexOf(p) === -1 && ['fn', 'jn'].indexOf(p) === -1;\n});\nif (unknown.length) { warn('Unbound prefixes: ' + unknown.join(', ')); }","typeGuard":"function isBoundPrefix(staticContext, prefix) {\n  return prefix === '' || prefix === 'fn' || prefix === 'jn' ||\n         !!staticContext.getNamespaceByPrefix(prefix);\n}","tryCatchPattern":"if (e.code === 'XPST0081') {\n  highlight(e.pos, 'Add: declare namespace ' + prefix + ' = \"...\"; or fix the typo');\n}","preventionTips":["Declare all namespaces at the top of the prolog before the body.","Prefer Q{uri}name form for one-off references in generated queries.","Watch for prefix typos, especially around xs/fn/local."],"tags":["xquery","qname","namespace","prefix-resolution"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}