01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.XPathContext;
04: import net.sf.saxon.om.InscopeNamespaceResolver;
05: import net.sf.saxon.om.Item;
06: import net.sf.saxon.om.NamespaceResolver;
07: import net.sf.saxon.om.NodeInfo;
08: import net.sf.saxon.trans.XPathException;
09: import net.sf.saxon.value.AnyURIValue;
10:
11: /**
12: * This class supports the function namespace-uri-for-prefix()
13: */
14:
15: public class NamespaceForPrefix extends SystemFunction {
16:
17: /**
18: * Evaluate the function
19: * @param context the XPath dynamic context
20: * @return the URI corresponding to the prefix supplied in the first argument, or null
21: * if the prefix is not in scope
22: * @throws XPathException if a failure occurs evaluating the arguments
23: */
24:
25: public Item evaluateItem(XPathContext context)
26: throws XPathException {
27: NodeInfo element = (NodeInfo) argument[1].evaluateItem(context);
28: String prefix = argument[0].evaluateItem(context)
29: .getStringValue();
30: if (prefix == null) {
31: return null;
32: }
33: NamespaceResolver resolver = new InscopeNamespaceResolver(
34: element);
35: String uri = resolver.getURIForPrefix(prefix, true);
36: if (uri == null) {
37: return null;
38: }
39: return new AnyURIValue(uri);
40: }
41:
42: }
43:
44: //
45: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
46: // you may not use this file except in compliance with the License. You may obtain a copy of the
47: // License at http://www.mozilla.org/MPL/
48: //
49: // Software distributed under the License is distributed on an "AS IS" basis,
50: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
51: // See the License for the specific language governing rights and limitations under the License.
52: //
53: // The Original Code is: all this file.
54: //
55: // The Initial Developer of the Original Code is Michael H. Kay
56: //
57: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
58: //
59: // Contributor(s): none.
60: //
|