public Sequence eval(StaticContext context, DocumentSet docs, Sequence contextSequence, Item contextItem) throws XPathException { if(!Type.subTypeOf(contextItem.getType(), Type.NODE)) throw new XPathException("last() can only be applied to nodes"); NodeProxy contextNode = (NodeProxy)contextItem; DocumentImpl doc = contextNode.getDoc(); int level = doc.getTreeLevel(contextNode.getGID()); long pid = (contextNode.getGID() - doc.getLevelStartPoint(level)) / doc.getTreeLevelOrder(level) + doc.getLevelStartPoint(level - 1); long f_gid = (pid - doc.getLevelStartPoint(level -1)) * doc.getTreeLevelOrder(level) + doc.getLevelStartPoint(level); long e_gid = f_gid + doc.getTreeLevelOrder(level); NodeSet set = ((NodeSet)contextSequence).getRange(doc, f_gid, e_gid); int len = set.getLength(); return new IntegerValue(len); }
public Sequence eval( DocumentSet docs, Sequence contextSequence, Item contextItem) throws XPathException { if(contextSequence == null || contextSequence.getLength() == 0) return Sequence.EMPTY_SEQUENCE; return new IntegerValue(contextSequence.getLength()); }
   public Sequence eval(StaticContext context, DocumentSet docs, Sequence contextSequence,   	Item contextItem) throws XPathException {   		if(!Type.subTypeOf(contextItem.getType(), Type.NODE))   			throw new XPathException("last() can only be applied to nodes");   		NodeProxy contextNode = (NodeProxy)contextItem;      DocumentImpl doc = contextNode.getDoc();      int level = doc.getTreeLevel(contextNode.getGID());      long pid = (contextNode.getGID() - doc.getLevelStartPoint(level)) /        doc.getTreeLevelOrder(level)        + doc.getLevelStartPoint(level - 1);      long f_gid = (pid - doc.getLevelStartPoint(level -1)) *        doc.getTreeLevelOrder(level) +        doc.getLevelStartPoint(level);      long e_gid = f_gid + doc.getTreeLevelOrder(level);      NodeSet set = ((NodeSet)contextSequence).getRange(doc, f_gid, e_gid);      int len = set.getLength();      return new IntegerValue(len);   }