1 package net.sf.saxon.functions; 2 import net.sf.saxon.expr.XPathContext; 3 import net.sf.saxon.om.*; 4 import net.sf.saxon.trans.XPathException; 5 import net.sf.saxon.value.AtomicValue; 6 import net.sf.saxon.value.QNameValue; 7 8 9 12 13 public class ResolveQName extends SystemFunction { 14 15 18 19 public Item evaluateItem(XPathContext context) throws XPathException { 20 AtomicValue arg0 = (AtomicValue)argument[0].evaluateItem(context); 21 if (arg0 == null) { 22 return null; 23 } 24 25 CharSequence qname = arg0.getStringValueCS(); 26 String [] parts; 27 try { 28 parts = Name.getQNameParts(qname); 29 } catch (QNameException err) { 30 dynamicError(err.getMessage(), "FOCA0002", context); 31 return null; 32 } 33 34 NodeInfo element = (NodeInfo)argument[1].evaluateItem(context); 35 SequenceIterator nsNodes = element.iterateAxis(Axis.NAMESPACE); 36 37 while (true) { 38 NodeInfo namespace = (NodeInfo)nsNodes.next(); 39 if (namespace==null) { 40 break; 41 } 42 String prefix = namespace.getLocalPart(); 43 if (prefix.equals(parts[0])) { 44 return new QNameValue(prefix, namespace.getStringValue(), parts[1]); 45 } 46 } 47 48 if (parts[0].equals("")) { 49 return new QNameValue("", null, parts[1]); 50 } 51 52 dynamicError( 53 "Namespace prefix '" + parts[0] + "' is not in scope for the selected element", "FONS0004", context); 54 return null; 55 } 56 57 } 58 59 60 61 62 63 | Popular Tags |