Altova XMLSpy 2024 Professional Edition

A formula in XML Grid View uses an XQuery 3.1 expression to calculate a result or generate a nodeset that can be stored in the document. A formula is defined with an XQuery 3.1 expression. For example, in the screenshot below, a formula named MinTemps has been created that generates the minimum, maximum, and average of the set of all minimum temperatures.


To create a formula, do the following:


1.Add a new node where you want to display the formula.

2.The node will be created by default as an element. Change the type of the node to Formula.

3.Double-click in the cell containing the f(x) icon and enter the name of the formula (see screenshot above).

4.You can click this icon to save the output of the formula to the document.

5.Double-click in the expression's cell and type in the XQuery expression, then click Enter.



Note the following points:


The context node of the formula's XQuery expression is the parent node of the formula node.

To add a new line in an expression, press Ctrl+Enter. This is useful if you want to display an expression over several lines for better readability.

The XQuery expressions of a document's formulas are stored in a special application metadata file located in your (My) Documents folder: Altova\XMLSpyCommon\json-metadata.json. Formulas will automatically be applied from this file when the document is re-opened in Grid View.

Formula expressions can additionally be saved as processing instructions in the document file itself when the document is saved. To do this, make sure that the Persistence option of Grid View Settings (Tools | Options | View | Grid View Settings) has been selected.

In Grid View, the result generated by a formula is displayed in the cell below the formula's XQuery expression and also stored in the application metadata file (see above).

If the Persistence option has been selected (see above), then a disk icon appears next to the XQuery expression. Toggle this icon on to save the formula's result in the document.

The formula's result will be stored as the content of an element which has the name you assigned the formula. For example: for the MinTemps formula shown in the screenshot above, the result will be stored in an element named MinTemps.

Whether the formula's result is stored in the document or not, it will be calculated and stored in the application metadata file (see above).


Formulas in tables

If all the cells of a table column (in Table Display) contain the same formula, then the formula is displayed only once—in the header of the column (see screenshot below). The results of the formula calculation, however, are displayed in the respective cells. The formula in the column header is a Grid View representation. In the XML document (see Text View), the formula is repeated for each table-row item.


If even a single formula of a cell is different, then the formula of each cell will be displayed. If all formulas of a table column are the same so that the formula appears in the header, and you now want to create a different formula for an individual cell, switch off Table Display and edit the formula of that cell. When you switch back to Table Display, formulas will be displayed in individual cells (for all cells).


© 2018-2024 Altova GmbH