1 package com.icl.saxon.functions; 2 import com.icl.saxon.*; 3 import com.icl.saxon.om.NodeInfo; 4 import com.icl.saxon.om.NodeEnumeration; 5 import com.icl.saxon.expr.*; 6 7 public class LocalName extends Function { 8 9 12 13 public String getName() { 14 return "local-name"; 15 }; 16 17 21 22 public int getDataType() { 23 return Value.STRING; 24 } 25 26 29 30 public Expression simplify() throws XPathException { 31 int numArgs = checkArgumentCount(0, 1); 32 if (numArgs==1) { 33 argument[0] = argument[0].simplify(); 34 } 35 return this; 36 } 37 38 41 42 public String evaluateAsString(Context c) throws XPathException { 43 if (getNumberOfArguments()==1) { 44 NodeEnumeration enum = argument[0].enumerate(c, true); 45 if (enum.hasMoreElements()) { 46 return enum.nextElement().getLocalName(); 47 } else { 48 return ""; 49 } 50 } else { 51 return c.getContextNodeInfo().getLocalName(); 52 } 53 } 54 55 58 59 public Value evaluate(Context c) throws XPathException { 60 return new StringValue(evaluateAsString(c)); 61 } 62 63 66 67 public int getDependencies() { 68 if (getNumberOfArguments()==1) { 69 return argument[0].getDependencies(); 70 } else { 71 return Context.CONTEXT_NODE; 72 } 73 } 74 75 78 79 public Expression reduce(int dep, Context c) throws XPathException { 80 if (getNumberOfArguments()==1) { 81 LocalName f = new LocalName(); 82 f.addArgument(argument[0].reduce(dep, c)); 83 f.setStaticContext(getStaticContext()); 84 return f.simplify(); 85 } else { 86 if ((dep & Context.CONTEXT_NODE)!=0) { 87 return evaluate(c); 88 } else { 89 return this; 90 } 91 } 92 } 93 94 } 95 96 97 98 99 | Popular Tags |