net.sf.saxon.instruct

Class ForEach

public class ForEach extends Instruction implements MappingFunction

Handler for xsl:for-each elements in a stylesheet.
Constructor Summary
ForEach(Expression select, Expression action)
Method Summary
voidcheckPermittedContents(SchemaType parentType, StaticContext env, boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type.
intcomputeDependencies()
Compute the dependencies of an expression, as the union of the dependencies of its subexpressions.
booleancreatesNewNodes()
Determine whether this instruction creates new nodes.
voiddisplay(int level, NamePool pool, PrintStream out)
Diagnostic print of expression structure.
ExpressiongetActionExpression()
Get the action expression (the content of the for-each)
intgetImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process().
intgetInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the items returned by this expression
SequenceIteratoriterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence.
IteratoriterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)
Objectmap(Item item, XPathContext context)
Map one item to a sequence.
Expressionoptimize(Optimizer opt, StaticContext env, ItemType contextItemType)
TailCallprocessLeavingTail(XPathContext context)
protected voidpromoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.
Expressionsimplify(StaticContext env)
Simplify an expression.
ExpressiontypeCheck(StaticContext env, ItemType contextItemType)

Constructor Detail

ForEach

public ForEach(Expression select, Expression action)

Method Detail

checkPermittedContents

public void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole)
Check that any elements and attributes constructed or returned by this expression are acceptable in the content model of a given complex type. It's always OK to say yes, since the check will be repeated at run-time. The process of checking element and attribute constructors against the content model of a complex type also registers the type of content expected of those constructors, so the static validation can continue recursively.

computeDependencies

public int computeDependencies()
Compute the dependencies of an expression, as the union of the dependencies of its subexpressions. (This is overridden for path expressions and filter expressions, where the dependencies of a subexpression are not all propogated). This method should be called only once, to compute the dependencies; after that, getDependencies should be used.

Returns: the depencies, as a bit-mask

createsNewNodes

public final boolean createsNewNodes()
Determine whether this instruction creates new nodes. This implementation returns true if the "action" creates new nodes. (Nodes created by the condition can't contribute to the result).

display

public void display(int level, NamePool pool, PrintStream out)
Diagnostic print of expression structure. The expression is written to the System.err output stream

Parameters: level indentation level for this expression out

getActionExpression

public Expression getActionExpression()
Get the action expression (the content of the for-each)

getImplementationMethod

public int getImplementationMethod()
An implementation of Expression must provide at least one of the methods evaluateItem(), iterate(), or process(). This method indicates which of these methods is provided. This implementation provides both iterate() and process() methods natively.

getInstructionNameCode

public int getInstructionNameCode()
Get the name of this instruction for diagnostic and tracing purposes

getItemType

public final ItemType getItemType(TypeHierarchy th)
Determine the data type of the items returned by this expression

Parameters: th

Returns: the data type

iterate

public SequenceIterator iterate(XPathContext context)
Return an Iterator to iterate over the values of a sequence. The value of every expression can be regarded as a sequence, so this method is supported for all expressions. This default implementation relies on the process() method: it "pushes" the results of the instruction to a sequence in memory, and then iterates over this in-memory sequence. In principle instructions should implement a pipelined iterate() method that avoids the overhead of intermediate storage.

Parameters: context supplies the context for evaluation

Returns: a SequenceIterator that can be used to iterate over the result of the expression

Throws: XPathException if any dynamic error occurs evaluating the expression

iterateSubExpressions

public Iterator iterateSubExpressions()
Get all the XPath expressions associated with this instruction (in XSLT terms, the expression present on attributes of the instruction, as distinct from the child instructions in a sequence construction)

map

public Object map(Item item, XPathContext context)
Map one item to a sequence.

Parameters: item The item to be mapped. If context is supplied, this must be the same as context.currentItem(). context The processing context. This is supplied only for mapping constructs that set the context node, position, and size. Otherwise it is null.

Returns: either (a) a SequenceIterator over the sequence of items that the supplied input item maps to, or (b) an Item if it maps to a single item, or (c) null if it maps to an empty sequence.

optimize

public Expression optimize(Optimizer opt, StaticContext env, ItemType contextItemType)

processLeavingTail

public TailCall processLeavingTail(XPathContext context)

promoteInst

protected void promoteInst(PromotionOffer offer)
Handle promotion offers, that is, non-local tree rewrites.

Parameters: offer The type of rewrite being offered

Throws: XPathException

simplify

public Expression simplify(StaticContext env)
Simplify an expression. This performs any static optimization (by rewriting the expression as a different expression).

Returns: the simplified expression

Throws: XPathException if an error is discovered during expression rewriting

typeCheck

public Expression typeCheck(StaticContext env, ItemType contextItemType)