Пример #1
0
 public Sequence<? extends Item> eval(Sequence<? extends Item> contextSeq, DynamicContext dynEnv)
     throws XQueryException {
   if (contextSeq == null) {
     throw new DynamicError("err:XPDY0002", "ContextItem is not set");
   }
   if (contextSeq instanceof XQNode) {
     final XQNode n = (XQNode) contextSeq;
     if (n.nodeKind() == NodeKind.ELEMENT) {
       if (n instanceof DMElement) {
         return ((DMElement) n).attribute(_nodeTest, dynEnv);
       } else {
         return new AttributeEmurationSequence((DTMElement) n, _nodeTest, dynEnv);
       }
     } else {
       return NodeSequence.<XQNode>emptySequence();
     }
   }
   final INodeSequence<XQNode> src = ProxyNodeSequence.wrap(contextSeq, dynEnv);
   final IFocus<XQNode> srcItor = src.iterator();
   if (srcItor.hasNext()) {
     final XQNode n = srcItor.next();
     if (srcItor.hasNext()) {
       srcItor.closeQuietly();
       reportError(
           "err:XPTY0020", "Context item is expected to be a node, but was node sequence.");
     }
     if (n.nodeKind() == NodeKind.ELEMENT) {
       srcItor.closeQuietly();
       return new AttributeEmurationSequence((DTMElement) n, _nodeTest, dynEnv);
     }
   }
   srcItor.closeQuietly();
   return NodeSequence.<XQNode>emptySequence();
 }
Пример #2
0
 @Override
 public Sequence<? extends Item> eval(Sequence<? extends Item> contextSeq, DynamicContext dynEnv)
     throws XQueryException {
   if (contextSeq == null) {
     throw new DynamicError("err:XPDY0002", "ContextItem is not set");
   }
   final INodeSequence<XQNode> src = ProxyNodeSequence.wrap(contextSeq, dynEnv);
   final IFocus<XQNode> srcItor = src.iterator();
   if (srcItor.hasNext()) {
     final XQNode n = srcItor.next();
     if (srcItor.hasNext()) {
       srcItor.closeQuietly();
       reportError(
           "err:XPTY0020", "Context item is expected to be a node, but was node sequence.");
     }
     final XQNode parent = n.parent();
     if (parent != null) {
       srcItor.closeQuietly();
       return new AncestorOrSelfEmuration(parent, getNodeTest(), dynEnv);
     }
   }
   srcItor.closeQuietly();
   return NodeSequence.<XQNode>emptySequence();
 }