Debian Codegraph @

net/sf/saxon/functions/ResolveQName.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.functions;
9
10 import net.sf.saxon.expr.XPathContext;
11 import net.sf.saxon.om.*;
12 import net.sf.saxon.trans.XPathException;
13 import net.sf.saxon.type.BuiltInAtomicType;
14 import net.sf.saxon.value.AtomicValue;
15 import net.sf.saxon.value.QNameValue;
16
17
18 /**
19 * This class supports the resolve-QName function in XPath 2.0
20 */
21
22 public class ResolveQName extends SystemFunction {
23
24 /**
25 * Evaluate the expression
26 *
27 * @param context the dynamic evaluation context
28 * @param arguments the values of the arguments, supplied as SequenceIterators
29 * @return the result of the evaluation, in the form of a SequenceIterator
30 * @throws net.sf.saxon.trans.XPathException
31 * if a dynamic error occurs during the evaluation of the expression
32 */
33 public ZeroOrOne<QNameValue> call(XPathContext context, Sequence[] arguments) throws XPathException {
34 AtomicValue lex = (AtomicValue) arguments[0].head();
35 return new ZeroOrOne<>(
36 lex == null ? null :
37 resolveQName(lex.getStringValueCS(), (NodeInfo) arguments[1].head()));
38 }
39
40 /**
41 * Static method to resolve a lexical QName against the namespace context of a supplied element node
42 *
43 * @param lexicalQName the lexical QName
44 * @param element the element node whose namespace context is to be used
45 * @return the result of resolving the QName
46 * @throws XPathException if the supplied value is not a valid lexical QName, or if its namespace
47 * prefix is not in scope
48 */
49
50 /*@Nullable*/
51 public static QNameValue resolveQName(CharSequence lexicalQName, NodeInfo element) throws XPathException {
52 NamespaceResolver resolver = new InscopeNamespaceResolver(element);
53 StructuredQName qName = StructuredQName.fromLexicalQName(lexicalQName, true, false, resolver);
54 return new QNameValue(qName, BuiltInAtomicType.QNAME);
55 }
56
57 }
58