Calculation Script Reference

This chapter provides an overview and usage of the namespace for the calculation script, and its elements and attributes.

1. Overview

Provides an overview of the namespace for calculation script.

1.1. Features and Usage

This namespace provides the scheme to perform a calculation in the XML document processed in VC.

1.2. Namespace URI Reference

The namespace URI reference of calculation script is located at http://xmlns.xfytec.com/calc. In the descriptions below, we use the namespace prefix calc: for an element used in calculation script.

1.3. How to Use Calculation Script in an XML Document

As for how to use a calculation script, there exists a method to apply a defined script, and the method to embed a calculation script into the attribute of any element (attribute embedding).

1.3.1. Application of Calculation Script

As for the method to use a calculation script by applying it to an XML document, there are the following two methods:

Specifying the External File in Your XML Document
Specific calculation script file can be applied to the XML document by describing the processing instruction within the XML document. To apply a particular calculation script file to your XML document, you write the com.xfytec processing instruction with the calculation parameter in the XML document, as shown below:
<?com.xfytec calculation href="URL of calculation script file" ?>
Embedding a XVCD into Your XML Document
A calculation script can be embedded into an XML document by describing an embedding. When using an embedded calculation script, you must specify the id attribute in the calc:calc element for the embedded calculation script. Then, in the com.xfytec calculation processing instruction, you write the ID value that you specified in id attribute of the calculation script.
<?com.xfytec calculation href="#Value of IDattribute of calc:calc element for an embedded calculation script" ?>
Describe the calculation script embedding into an XML document within the root element of the target XML document.

If multiple calculation scripts are applied in com.xfytec calculation processing instruction, the first described calculation script takes precedence.

1.3.2. Attribute Embedding

When you describe a calculation script using attribute embedding, specify a calculation for the calc:expression global attribute, and then specify the attribute for the element into which calculation script is embedded.

1.4. Performing a Calculation

The timing of performing a calculation differs depending on whether the content of the node to which the expression described in the calculation script refers is changed or whether the expression described in the calculation script itself is changed.

If the content of the node to which the expression described in the calculation script refers is changed:
Calculation is performed automatically.
If the expression described in the calculation script is added or changed:
The calculation script assigned to an XML document is different from the calculation script described by attribute embedding.
  • If the calculation script assigned to an XML document is added or changed, the calculation will be performed when the document is loaded again.
  • If the calculation script described by attribute embedding is added or changed, the calculation will be performed when editing the calculation script is fixed.
If the calculation script is deleted:
If the calculation script assigned to an XML document is deleted, the calc:expression global attribute is deleted or the element where the calc:expression global attribute is set is deleted, the calculation based on the calculation script is not executed.

If the reference between the calculation and the referred node becomes circular, the calculation will be done only once without iterating.

2. Elements and Attributes Defined in the Namespace for Calculation Script

Explains the elements and attributes defined in the namespace for the calculation script.

2.1. Calculation Script

Elements and attributes used to describe the calculation script are listed below.

calc:calc Element

Includes the whole calculation script.

Attribute:
id

Identifies the calc:calc element. It can be an ID value. If a calculation script is embedded into an XML document, it identifies the calc:calc element by the ID value specified in this attribute.

If omitted, the attribute value is not assumed to be set.

version (mandatory)

Sets calculation script version number. This attribute is mandatory. This must be 1.0.

Content:

In calc:calc element, one or as many calc:bind elements as needed can be specified.

calc:bind Element

Specifies the calculation and the node to output the calculation result. It can be a node set for the destination to output the calculation result. If a node set is specified, the calculation result is output to each element within the node set.

Attribute:
target (mandatory)

Specifies a node or a node set to output the calculation result. It can be an XPath expression. After an XPath expression's evaluation, the destination to output calculation result may vary according to the obtained node type.

Text node
Calculation result is output to the text node.
Element node
The first text node of child nodes is obtained and the calculation result is output to the text node.
Attribute node
Does nothing.
Node set
Calculation result is output according to each node type in the node set.

The calculation is evaluated on the node specified in this attribute as a context node. If the node set is specified, the calculation is evaluated on each node in the node set as a context node.

expression (mandatory)

Sets an expression. It can be an XPath expression. The node referring to a number can be specified for the calculation. To specify the node, not only the absolute path, but also the relative path to the node specified in the target attribute or node set, is available.

Content:

The calc:bind element is empty.

2.2. Attribute Embedding

The global attributes available when you describe a calculation script using attribute embedding are listed below.

calc:expression Attribute

Global attribute used when you describe a calculation script within any element of XML document using attribute embedding. Specify XPath expression representing the calculation for the value.