/** * Evaluate the variable. That is, * get the value of the select expression if present or the content * of the element otherwise, either as a tree or as a sequence * * @param context the XPath dynamic context * @return the result of evaluating the variable * @throws net.sf.saxon.trans.XPathException * if evaluation of the select expression fails * with a dynamic error */ public Sequence<?> getSelectValue(XPathContext context) throws XPathException { Expression select = getSelectExpression(); if (select == null) { throw new AssertionError("Internal error: No select expression"); // The value of the variable is a sequence of nodes and/or atomic values } else if (select instanceof Literal) { // fast path for common case return ((Literal)select).getValue(); } else { // There is a select attribute: do a lazy evaluation of the expression, // which will already contain any code to force conversion to the required type. int savedOutputState = context.getTemporaryOutputState(); context.setTemporaryOutputState(StandardNames.XSL_WITH_PARAM); Sequence<?> result = evaluator.evaluate(select, context); context.setTemporaryOutputState(savedOutputState); return result; } }
/** * Evaluate the variable. That is, * get the value of the select expression if present or the content * of the element otherwise, either as a tree or as a sequence * * @param context the XPath dynamic context * @return the result of evaluating the variable * @throws net.sf.saxon.trans.XPathException * if evaluation of the select expression fails * with a dynamic error */ public Sequence<?> getSelectValue(XPathContext context) throws XPathException { // There is a select attribute: do a lazy evaluation of the expression, // which will already contain any code to force conversion to the required type. if (evaluator == null) { computeEvaluator(); } int savedOutputState = context.getTemporaryOutputState(); context.setTemporaryOutputState(StandardNames.XSL_WITH_PARAM); Sequence<?> result = evaluator.evaluate(selectOp.getChildExpression(), context); context.setTemporaryOutputState(savedOutputState); return result; }
/** * Evaluate the variable. That is, * get the value of the select expression if present or the content * of the element otherwise, either as a tree or as a sequence * * @param context the XPath dynamic context * @return the result of evaluating the variable * @throws net.sf.saxon.trans.XPathException * if evaluation of the select expression fails * with a dynamic error */ public Sequence<?> getSelectValue(XPathContext context) throws XPathException { // There is a select attribute: do a lazy evaluation of the expression, // which will already contain any code to force conversion to the required type. if (evaluator == null) { computeEvaluator(); } int savedOutputState = context.getTemporaryOutputState(); context.setTemporaryOutputState(StandardNames.XSL_WITH_PARAM); Sequence<?> result = evaluator.evaluate(selectOp.getChildExpression(), context); context.setTemporaryOutputState(savedOutputState); return result; }
/** * Evaluate the variable. That is, * get the value of the select expression if present or the content * of the element otherwise, either as a tree or as a sequence * * @param context the XPath dynamic context * @return the result of evaluating the variable * @throws net.sf.saxon.trans.XPathException * if evaluation of the select expression fails * with a dynamic error */ public Sequence<?> getSelectValue(XPathContext context) throws XPathException { Expression select = getSelectExpression(); if (select == null) { throw new AssertionError("Internal error: No select expression"); // The value of the variable is a sequence of nodes and/or atomic values } else if (select instanceof Literal) { // fast path for common case return ((Literal)select).getValue(); } else { // There is a select attribute: do a lazy evaluation of the expression, // which will already contain any code to force conversion to the required type. int savedOutputState = context.getTemporaryOutputState(); context.setTemporaryOutputState(StandardNames.XSL_WITH_PARAM); Sequence<?> result = evaluator.evaluate(select, context); context.setTemporaryOutputState(savedOutputState); return result; } }
/** * Evaluate the variable. * * @param context the dynamic evaluation context * @return the result of evaluating the expression that is bound to the variable */ public Sequence<?> eval(XPathContext context) throws XPathException { if (evaluator == null) { setEvaluator(ExpressionTool.lazyEvaluator(getSequence(), getNominalReferenceCount() > 1)); } try { int savedOutputState = context.getTemporaryOutputState(); context.setTemporaryOutputState(StandardNames.XSL_VARIABLE); Sequence<?> result = evaluator.evaluate(getSequence(), context); context.setTemporaryOutputState(savedOutputState); return result; } catch (ClassCastException e) { // Probably the evaluation mode is wrong, as a result of an expression rewrite. Try again. assert false; int savedOutputState = context.getTemporaryOutputState(); context.setTemporaryOutputState(StandardNames.XSL_VARIABLE); Sequence<?> result = Evaluator.EAGER_SEQUENCE.evaluate(getSequence(), context); context.setTemporaryOutputState(savedOutputState); return result; } }
/** * Evaluate the variable. * * @param context the dynamic evaluation context * @return the result of evaluating the expression that is bound to the variable */ public Sequence<?> eval(XPathContext context) throws XPathException { if (evaluator == null) { setEvaluator(ExpressionTool.lazyEvaluator(getSequence(), getNominalReferenceCount() > 1)); } try { int savedOutputState = context.getTemporaryOutputState(); context.setTemporaryOutputState(StandardNames.XSL_VARIABLE); Sequence<?> result = evaluator.evaluate(getSequence(), context); context.setTemporaryOutputState(savedOutputState); return result; } catch (ClassCastException e) { // Probably the evaluation mode is wrong, as a result of an expression rewrite. Try again. assert false; int savedOutputState = context.getTemporaryOutputState(); context.setTemporaryOutputState(StandardNames.XSL_VARIABLE); Sequence<?> result = Evaluator.EAGER_SEQUENCE.evaluate(getSequence(), context); context.setTemporaryOutputState(savedOutputState); return result; } }
public MergeKeyMappingFunction(XPathContext baseContext, MergeSource ms) { this.baseContext = baseContext; this.ms = ms; keyContext = baseContext.newMinorContext(); keyContext.setTemporaryOutputState(StandardNames.XSL_MERGE_KEY); manualIterator = new ManualIterator<>(); manualIterator.setPosition(1); keyContext.setCurrentIterator(manualIterator); } public SequenceIterator<ExternalObject<ItemWithMergeKeys>> map(XPathContext context)
public MergeKeyMappingFunction(XPathContext baseContext, MergeSource ms) { this.baseContext = baseContext; this.ms = ms; keyContext = baseContext.newMinorContext(); keyContext.setTemporaryOutputState(StandardNames.XSL_MERGE_KEY); manualIterator = new ManualIterator<>(); manualIterator.setPosition(1); keyContext.setCurrentIterator(manualIterator); } public SequenceIterator<ExternalObject<ItemWithMergeKeys>> map(XPathContext context)
/** * Create a sorted iterator * * @param context the dynamic XPath evaluation context * @param base an iterator over the sequence to be sorted * @param sortKeyEvaluator an object that allows the n'th sort key for a given item to be evaluated * @param comparators an array of AtomicComparers, one for each sort key, for comparing sort key values * @param createNewContext true if sort keys are computed relative to the item being sorted (as in XSLT but not XQuery) */ public SortedIterator(XPathContext context, SequenceIterator<?> base, SortKeyEvaluator sortKeyEvaluator, AtomicComparer[] comparators, boolean createNewContext) { if (createNewContext) { this.context = context.newMinorContext(); this.base = this.context.trackFocus(base); this.context.setTemporaryOutputState(StandardNames.XSL_SORT); } else { this.base = base; this.context = context; } this.sortKeyEvaluator = sortKeyEvaluator; this.comparators = new AtomicComparer[comparators.length]; for (int n = 0; n < comparators.length; n++) { this.comparators[n] = comparators[n].provideContext(context); } // Avoid doing the sort until the user wants the first item. This is because // sometimes the user only wants to know whether the collection is empty. }
/** * Create a sorted iterator * * @param context the dynamic XPath evaluation context * @param base an iterator over the sequence to be sorted * @param sortKeyEvaluator an object that allows the n'th sort key for a given item to be evaluated * @param comparators an array of AtomicComparers, one for each sort key, for comparing sort key values * @param createNewContext true if sort keys are computed relative to the item being sorted (as in XSLT but not XQuery) */ public SortedIterator(XPathContext context, SequenceIterator<?> base, SortKeyEvaluator sortKeyEvaluator, AtomicComparer[] comparators, boolean createNewContext) { if (createNewContext) { this.context = context.newMinorContext(); this.base = this.context.trackFocus(base); this.context.setTemporaryOutputState(StandardNames.XSL_SORT); } else { this.base = base; this.context = context; } this.sortKeyEvaluator = sortKeyEvaluator; this.comparators = new AtomicComparer[comparators.length]; for (int n = 0; n < comparators.length; n++) { this.comparators[n] = comparators[n].provideContext(context); } // Avoid doing the sort until the user wants the first item. This is because // sometimes the user only wants to know whether the collection is empty. }
private SequenceIterator getInputIterator(AtomicComparer[] comps, SequenceIterator inputIterator, MergeSource ms, XPathContext c2) throws XPathException { XPathContext c4 = c2.newMinorContext(); c4.setTemporaryOutputState(StandardNames.XSL_MERGE_KEY); FocusIterator<?> rowIntr = c4.trackFocus(ms.getRowSelect().iterate(c2)); MergeKeyMappingFunction addMergeKeys = new MergeKeyMappingFunction(c4, ms); ContextMappingIterator<ExternalObject<ItemWithMergeKeys>> contextMapKeysItr = new ContextMappingIterator<>(addMergeKeys, c4); inputIterator = makeMergeIterator(inputIterator, comps, ms, contextMapKeysItr); return inputIterator; }
private SequenceIterator getInputIterator(AtomicComparer[] comps, SequenceIterator inputIterator, MergeSource ms, XPathContext c2) throws XPathException { XPathContext c4 = c2.newMinorContext(); c4.setTemporaryOutputState(StandardNames.XSL_MERGE_KEY); FocusIterator<?> rowIntr = c4.trackFocus(ms.getRowSelect().iterate(c2)); MergeKeyMappingFunction addMergeKeys = new MergeKeyMappingFunction(c4, ms); ContextMappingIterator<ExternalObject<ItemWithMergeKeys>> contextMapKeysItr = new ContextMappingIterator<>(addMergeKeys, c4); inputIterator = makeMergeIterator(inputIterator, comps, ms, contextMapKeysItr); return inputIterator; }