Package net.sf.saxon.expr.instruct

## Class ResultDocument

- java.lang.Object
- - net.sf.saxon.expr.Expression
  - - net.sf.saxon.expr.instruct.Instruction
    - - net.sf.saxon.expr.instruct.ResultDocument

- All Implemented Interfaces:
    `ContextOriginator`, `ExportAgent`, `InstructionWithComplexContent`, `TailCallReturner`, `ValidatingInstruction`, `Locatable`, `IdentityComparable`, `Traceable`

      public class ResultDocument
      extends Instruction
      implements ValidatingInstruction, InstructionWithComplexContent, ContextOriginator

  The compiled form of an xsl:result-document element in the stylesheet.

  The xsl:result-document element takes an attribute href="filename". The filename will often contain parameters, e.g. {position()} to ensure that a different file is produced for each element instance.

  There is a further attribute "format" which determines the format of the output file, it identifies the name of an xsl:output element containing the output format details. In addition, individual serialization properties may be specified as attributes. These are attribute value templates, so they may need to be computed at run-time.

- - ### Field Summary

    - ### Fields inherited from class net.sf.saxon.expr.Expression

      `EFFECTIVE_BOOLEAN_VALUE, EVALUATE_METHOD, ITEM_FEED_METHOD, ITERATE_METHOD, MAX_COST, MAX_SEQUENCE_LENGTH, MAX_STRING_LENGTH, PROCESS_METHOD, staticProperties, UNBOUNDED_LOWER, UNBOUNDED_UPPER, UPDATE_METHOD, WATCH_METHOD`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ResultDocument​(java.util.Properties globalProperties, java.util.Properties localProperties, Expression href, Expression formatExpression, int validationAction, SchemaType schemaType, java.util.Map<StructuredQName,​Expression> serializationAttributes, CharacterMapIndex characterMapIndex)` | Create a result-document instruction

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `PathMap.PathMapNodeSet` | `addToPathMap​(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet)` | Add a representation of this expression to a PathMap.
    `static void` | `checkAcceptableUri​(XPathContext context, java.lang.String uri)` |
    `Expression` | `copy​(RebindingMap rebindings)` | Copy an expression.
    `void` | `export​(ExpressionPresenter out)` | Diagnostic print of expression structure.
    `java.util.Properties` | `gatherOutputProperties​(XPathContext context)` | Create a properties object that combines the serialization properties specified on the xsl:result-document itself with those specified in the referenced xsl:output declaration
    `CharacterMapIndex` | `getCharacterMapIndex()` |
    `Expression` | `getContentExpression()` | Get the subexpression that is used to evaluated the content, that is, the contained sequence constructor
    `Expression` | `getFormatExpression()` |
    `Expression` | `getHref()` |
    `int` | `getInstructionNameCode()` | Get the name of this instruction for diagnostic and tracing purposes (the string "xsl:result-document")
    `int` | `getIntrinsicDependencies()` | Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions.
    `ItemType` | `getItemType()` | Get the item type of the items returned by evaluating this instruction
    `SchemaType` | `getSchemaType()` | Get the schema type chosen for validation; null if not defined
    `java.lang.String` | `getStaticSerializationProperty​(StructuredQName name)` | Get the value of a serialization property if it is statically known
    `java.lang.String` | `getStreamerName()` | Get the (partial) name of a class that supports streaming of this kind of expression
    `int` | `getValidationAction()` | Get the validation mode for this instruction
    `ParseOptions` | `getValidationOptions()` | Get the validation options
    `boolean` | `isAsynchronous()` | Ask if the instruction is to be asynchronous
    `boolean` | `isMultiThreaded​(Configuration config)` | Ask whether the expression is multithreaded (that is, whether its operands are evaluated in parallel)
    `boolean` | `isResolveAgainstStaticBase()` |
    `static Receiver` | `makeReceiver​(java.lang.String hrefValue, java.lang.String baseURI, XPathContext context, ResultDocumentResolver resolver, SerializationProperties params, boolean resolveAgainstStaticBase)` |
    `java.lang.Iterable<Operand>` | `operands()` | Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression.
    `Expression` | `optimize​(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)` | Perform optimisation of an expression and its subexpressions.
    `void` | `process​(Expression content, XPathContext context)` |
    `void` | `processInstruction​(Expression content, XPathContext context)` | Evaluation method designed for calling from compiled bytecode.
    `TailCall` | `processLeavingTail​(Outputter output, XPathContext context)` | ProcessLeavingTail: called to do the real work of this instruction.
    `ComplexContentOutputter` | `processLeft​(XPathContext context)` |
    `static void` | `processXslOutputElement​(NodeInfo element, java.util.Properties props, XPathContext c)` | Construct a set of output properties from an xsl:output element supplied at run-time
    `void` | `setAsynchronous​(boolean async)` |
    `void` | `setContentExpression​(Expression content)` | Set the expression that constructs the content
    `void` | `setFormatExpression​(Expression formatExpression)` |
    `void` | `setHref​(Expression href)` |
    `void` | `setSchemaType​(SchemaType type)` | Set the schema type to be used for validation
    `static void` | `setSerializationProperty​(java.util.Properties details, java.lang.String uri, java.lang.String lname, java.lang.String value, NamespaceResolver nsResolver, boolean prevalidated, Configuration config)` | Validate a serialization property and add its value to a Properties collection
    `void` | `setUseStaticBaseUri​(boolean staticBase)` | Set whether the the instruction should resolve the href relative URI against the static base URI (rather than the dynamic base output URI)
    `void` | `setValidationAction​(int mode, SchemaType schemaType)` | Set the validation mode for the new document
    `static void` | `traceDestination​(XPathContext context, javax.xml.transform.Result result)` |
    `Expression` | `typeCheck​(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo)` | Perform type checking of an expression and its subexpressions.

    - ### Methods inherited from class net.sf.saxon.expr.instruct.Instruction

      `alwaysCreatesNewNodes, assembleParams, assembleTunnelParams, computeCardinality, computeSpecialProperties, dynamicError, evaluateAsString, evaluateItem, getExpressionName, getImplementationMethod, getNetCost, getSourceLocator, isInstruction, isXSLT, iterate, mayCreateNewNodes, process, someOperandCreatesNewNodes`

    - ### Methods inherited from class net.sf.saxon.expr.Expression

      `adoptChildExpression, allowExtractingCommonSubexpressions, checkedOperands, checkForUpdatingSubexpressions, checkPermittedContents, computeDependencies, computeHashCode, computeStaticProperties, dynamicError, effectiveBooleanValue, equals, evaluatePendingUpdates, explain, getCardinality, getConfiguration, getCost, getDependencies, getEvaluationMethod, getExtraProperty, getIntegerBounds, getInterpretedExpression, getLocalRetainedStaticContext, getLocation, getObjectName, getPackageData, getParentExpression, getProperties, getProperty, getRetainedStaticContext, getScopingExpression, getSlotsUsed, getSpecialProperties, getStaticBaseURI, getStaticBaseURIString, getStaticType, getStaticUType, getTracingTag, hasCompatibleStaticContext, hashCode, hasSpecialProperty, hasVariableBinding, identityHashCode, implementsStaticTypeCheck, isCallOn, isEqual, isIdentical, isLiftable, isStaticPropertiesKnown, isSubtreeExpression, isUpdatingExpression, isVacuousExpression, markTailFunctionCalls, operandList, operandSparseList, optimizeChildren, prepareForStreaming, resetLocalStaticProperties, restoreParentPointers, setEvaluationMethod, setExtraProperty, setFiltered, setFlattened, setLocation, setParentExpression, setRetainedStaticContext, setRetainedStaticContextLocally, setRetainedStaticContextThoroughly, setStaticProperty, simplify, simplifyChildren, staticTypeCheck, suppressValidation, toPattern, toShortString, toString, typeCheckChildren, typeError, unordered, verifyParentPointers`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface net.sf.saxon.trace.Traceable

      `gatherProperties`

- - ### Constructor Detail

    - #### ResultDocument

          public ResultDocument​(java.util.Properties globalProperties,
                                java.util.Properties localProperties,
                                Expression href,
                                Expression formatExpression,
                                int validationAction,
                                SchemaType schemaType,
                                java.util.Map<StructuredQName,​Expression> serializationAttributes,
                                CharacterMapIndex characterMapIndex)

      Create a result-document instruction
      Parameters:
        `globalProperties` - properties defined on static xsl:output
        `localProperties` - non-AVT properties defined on result-document element
        `href` - href attribute of instruction
        `formatExpression` - format attribute of instruction
        `validationAction` - for example `Validation.STRICT`
        `schemaType` - schema type against which output is to be validated
        `serializationAttributes` - computed local properties

  - ### Method Detail

    - #### setContentExpression

          public void setContentExpression​(Expression content)

      Set the expression that constructs the content
      Parameters:
        `content` - the expression defining the content of the result document

    - #### setSchemaType

          public void setSchemaType​(SchemaType type)

      Set the schema type to be used for validation
      Parameters:
        `type` - the type to be used for validation. (For a document constructor, this is the required type of the document element)

    - #### getSchemaType

          public SchemaType getSchemaType()

      Get the schema type chosen for validation; null if not defined
      Specified by:
        `getSchemaType` in interface `ValidatingInstruction`
      Returns:
        the type to be used for validation. (For a document constructor, this is the required type of the document element)

    - #### isResolveAgainstStaticBase

          public boolean isResolveAgainstStaticBase()

    - #### getValidationOptions

          public ParseOptions getValidationOptions()

      Get the validation options
      Returns:
        the validation options for the content of the constructed node. May be null if no validation was requested.

    - #### setValidationAction

          public void setValidationAction​(int mode,
                                          SchemaType schemaType)

      Set the validation mode for the new document
      Parameters:
        `mode` - the validation mode, for example `Validation.STRICT`
        `schemaType` - the required type (for validation by type). Null if not validating by type

    - #### getValidationAction

          public int getValidationAction()

      Get the validation mode for this instruction
      Specified by:
        `getValidationAction` in interface `ValidatingInstruction`
      Returns:
        the validation mode, for example `Validation.STRICT` or `Validation.PRESERVE`

    - #### getFormatExpression

          public Expression getFormatExpression()

    - #### setUseStaticBaseUri

          public void setUseStaticBaseUri​(boolean staticBase)

      Set whether the the instruction should resolve the href relative URI against the static base URI (rather than the dynamic base output URI)
      Parameters:
        `staticBase` - set to true by fn:put(), to resolve against the static base URI of the query. Default is false, which causes resolution against the base output URI obtained dynamically from the Controller

    - #### setAsynchronous

          public void setAsynchronous​(boolean async)

    - #### isAsynchronous

          public boolean isAsynchronous()

      Ask if the instruction is to be asynchronous
      Returns:
        true unless saxon:asynchronous="no" was specified (regardless of other options that might suppress asychronous operation)

    - #### isMultiThreaded

          public boolean isMultiThreaded​(Configuration config)

      Description copied from class: `Expression`
      Ask whether the expression is multithreaded (that is, whether its operands are evaluated in parallel)
      Overrides:
        `isMultiThreaded` in class `Expression`
      Parameters:
        `config` - the Saxon configuration
      Returns:
        true if execution will be multithreaded

    - #### typeCheck

          public Expression typeCheck​(ExpressionVisitor visitor,
                                      ContextItemStaticInfo contextInfo)
                               throws XPathException

      Description copied from class: `Expression`
      Perform type checking of an expression and its subexpressions. This is the second phase of static optimization.

      This checks statically that the operands of the expression have the correct type; if necessary it generates code to do run-time type checking or type conversion. A static type error is reported only if execution cannot possibly succeed, that is, if a run-time type error is inevitable. The call may return a modified form of the expression.

      This method is called after all references to functions and variables have been resolved to the declaration of the function or variable. However, the types of such functions and variables may not be accurately known if they have not been explicitly declared.

      Overrides:
        `typeCheck` in class `Expression`
      Parameters:
        `visitor` - an expression visitor
        `contextInfo` - Information available statically about the context item: whether it is (possibly) absent; its static type; its streaming posture.
      Returns:
        the original expression, rewritten to perform necessary run-time type checks, and to perform other type-related optimizations
      Throws:
        `XPathException` - if an error is discovered during this phase (typically a type error)

    - #### getIntrinsicDependencies

          public int getIntrinsicDependencies()

      Description copied from class: `Expression`
      Determine the intrinsic dependencies of an expression, that is, those which are not derived from the dependencies of its subexpressions. For example, position() has an intrinsic dependency on the context position, while (position()+1) does not. The default implementation of the method returns 0, indicating "no dependencies".
      Overrides:
        `getIntrinsicDependencies` in class `Expression`
      Returns:
        a set of bit-significant flags identifying the "intrinsic" dependencies. The flags are documented in class net.sf.saxon.value.StaticProperty

    - #### optimize

          public Expression optimize​(ExpressionVisitor visitor,
                                     ContextItemStaticInfo contextInfo)
                              throws XPathException

      Description copied from class: `Expression`
      Perform optimisation of an expression and its subexpressions. This is the third and final phase of static optimization.

      This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.

      Overrides:
        `optimize` in class `Expression`
      Parameters:
        `visitor` - an expression visitor
        `contextInfo` - the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set to `Type.ITEM_TYPE`
      Returns:
        the original expression, rewritten if appropriate to optimize execution
      Throws:
        `XPathException` - if an error is discovered during this phase (typically a type error)

    - #### copy

          public Expression copy​(RebindingMap rebindings)

      Copy an expression. This makes a deep copy.
      Specified by:
        `copy` in class `Expression`
      Parameters:
        `rebindings` - variable bindings that need to be changed
      Returns:
        the copy of the original expression

    - #### getInstructionNameCode

          public int getInstructionNameCode()

      Get the name of this instruction for diagnostic and tracing purposes (the string "xsl:result-document")
      Overrides:
        `getInstructionNameCode` in class `Instruction`
      Returns:
        a code identifying the instruction: typically but not always the fingerprint of a name in the XSLT namespace

    - #### getItemType

          public ItemType getItemType()

      Get the item type of the items returned by evaluating this instruction
      Overrides:
        `getItemType` in class `Instruction`
      Returns:
        the static item type of the instruction. This is empty: the result-document instruction returns nothing.

    - #### operands

          public java.lang.Iterable<Operand> operands()

      Description copied from class: `Expression`
      Get the immediate sub-expressions of this expression, with information about the relationship of each expression to its parent expression. Default implementation works off the results of iterateSubExpressions()

      If the expression is a Callable, then it is required that the order of the operands returned by this function is the same as the order of arguments supplied to the corresponding call() method.

      Specified by:
        `operands` in class `Instruction`
      Returns:
        an iterator containing the sub-expressions of this expression

    - #### addToPathMap

          public PathMap.PathMapNodeSet addToPathMap​(PathMap pathMap,
                                                     PathMap.PathMapNodeSet pathMapNodeSet)

      Add a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited by an expression in a source tree.

      The default implementation of this method assumes that an expression does no navigation other than the navigation done by evaluating its subexpressions, and that the subexpressions are evaluated in the same context as the containing expression. The method must be overridden for any expression where these assumptions do not hold. For example, implementations exist for AxisExpression, ParentExpression, and RootExpression (because they perform navigation), and for the doc(), document(), and collection() functions because they create a new navigation root. Implementations also exist for PathExpression and FilterExpression because they have subexpressions that are evaluated in a different context from the calling expression.

      Overrides:
        `addToPathMap` in class `Expression`
      Parameters:
        `pathMap` - the PathMap to which the expression should be added
        `pathMapNodeSet` - the PathMapNodeSet to which the paths embodied in this expression should be added
      Returns:
        the pathMapNodeSet representing the points in the source document that are both reachable by this expression, and that represent possible results of this expression. For an expression that does navigation, it represents the end of the arc in the path map that describes the navigation route. For other expressions, it is the same as the input pathMapNode.

    - #### processLeavingTail

          public TailCall processLeavingTail​(Outputter output,
                                             XPathContext context)
                                      throws XPathException

      Description copied from class: `Instruction`
      ProcessLeavingTail: called to do the real work of this instruction. This method must be implemented in each subclass. The results of the instruction are written to the current Receiver, which can be obtained via the Controller.
      Specified by:
        `processLeavingTail` in interface `TailCallReturner`
      Specified by:
        `processLeavingTail` in class `Instruction`
      Parameters:
        `output` - the destination for the result
        `context` - The dynamic context of the transformation, giving access to the current node, the current variables, etc.
      Returns:
        null if the instruction has completed execution; or a TailCall indicating a function call or template call that is delegated to the caller, to be made after the stack has been unwound so as to save stack space.
      Throws:
        `XPathException` - if a dynamic error occurs during the evaluation of the instruction

    - #### process

          public void process​(Expression content,
                              XPathContext context)
                       throws XPathException

      Throws:
        `XPathException`

    - #### processInstruction

          public void processInstruction​(Expression content,
                                         XPathContext context)
                                  throws XPathException

      Evaluation method designed for calling from compiled bytecode.
      Parameters:
        `content` - The content expression. When called from bytecode, this will be the compiled version of the interpreted content expression
        `context` - dynamic evaluation context
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### processLeft

          public ComplexContentOutputter processLeft​(XPathContext context)
                                              throws XPathException

      Throws:
        `XPathException`

    - #### getCharacterMapIndex

          public CharacterMapIndex getCharacterMapIndex()

    - #### makeReceiver

          public static Receiver makeReceiver​(java.lang.String hrefValue,
                                              java.lang.String baseURI,
                                              XPathContext context,
                                              ResultDocumentResolver resolver,
                                              SerializationProperties params,
                                              boolean resolveAgainstStaticBase)
                                       throws XPathException

      Throws:
        `XPathException`

    - #### traceDestination

          public static void traceDestination​(XPathContext context,
                                              javax.xml.transform.Result result)

    - #### checkAcceptableUri

          public static void checkAcceptableUri​(XPathContext context,
                                                java.lang.String uri)
                                         throws XPathException

      Throws:
        `XPathException`

    - #### gatherOutputProperties

          public java.util.Properties gatherOutputProperties​(XPathContext context)
                                                      throws XPathException

      Create a properties object that combines the serialization properties specified on the xsl:result-document itself with those specified in the referenced xsl:output declaration
      Parameters:
        `context` - The XPath evaluation context
      Returns:
        the assembled properties
      Throws:
        `XPathException` - if invalid properties are found

    - #### getStaticSerializationProperty

          public java.lang.String getStaticSerializationProperty​(StructuredQName name)

      Get the value of a serialization property if it is statically known
      Parameters:
        `name` - the name of the serialization property
      Returns:
        the value of the serialization property if known statically; or null otherwise

    - #### setSerializationProperty

          public static void setSerializationProperty​(java.util.Properties details,
                                                      java.lang.String uri,
                                                      java.lang.String lname,
                                                      java.lang.String value,
                                                      NamespaceResolver nsResolver,
                                                      boolean prevalidated,
                                                      Configuration config)
                                               throws XPathException

      Validate a serialization property and add its value to a Properties collection
      Parameters:
        `details` - the properties to be updated
        `uri` - the uri of the property name
        `lname` - the local part of the property name
        `value` - the value of the serialization property. In the case of QName-valued values, this will use lexical QNames if prevalidated is false and a NamespaceResolver is supplied; otherwise they will use Clark-format names
        `nsResolver` - resolver for lexical QNames; not needed if prevalidated, or if QNames are supplied in Clark format
        `prevalidated` - true if values are already known to be valid and lexical QNames have been expanded into Clark notation
        `config` - the Saxon configuration
      Throws:
        `XPathException` - if any serialization property has an invalid value

    - #### export

          public void export​(ExpressionPresenter out)
                      throws XPathException

      Diagnostic print of expression structure. The abstract expression tree is written to the supplied output destination.
      Specified by:
        `export` in interface `ExportAgent`
      Specified by:
        `export` in class `Expression`
      Parameters:
        `out` - the expression presenter used to display the structure
      Throws:
        `XPathException` - if the export fails, for example if an expression is found that won't work in the target environment.

    - #### processXslOutputElement

          public static void processXslOutputElement​(NodeInfo element,
                                                     java.util.Properties props,
                                                     XPathContext c)
                                              throws XPathException

      Construct a set of output properties from an xsl:output element supplied at run-time
      Parameters:
        `element` - an xsl:output element
        `props` - Properties object to which will be added the values of those serialization properties that were specified
        `c` - the XPath dynamic context
      Throws:
        `XPathException` - if a dynamic error occurs

    - #### getStreamerName

          public java.lang.String getStreamerName()

      Get the (partial) name of a class that supports streaming of this kind of expression
      Overrides:
        `getStreamerName` in class `Expression`
      Returns:
        the partial name of a class that can be instantiated to provide streaming support in Saxon-EE, or null if there is no such class

    - #### getHref

          public Expression getHref()

    - #### setHref

          public void setHref​(Expression href)

    - #### setFormatExpression

          public void setFormatExpression​(Expression formatExpression)

    - #### getContentExpression

          public Expression getContentExpression()

      Description copied from interface: `InstructionWithComplexContent`
      Get the subexpression that is used to evaluated the content, that is, the contained sequence constructor
      Specified by:
        `getContentExpression` in interface `InstructionWithComplexContent`
      Returns:
        the expression that constructs the content