Please enable JavaScript to view this site.

Altova MapForce 2021 Professional Edition

Returns true if the connected node exists; false otherwise. Since it returns a Boolean value, this function is typically used with filters, to filter out only records which have (or perhaps do not have) a child element or attribute.

mf-func-exists

 

Languages

Built-in, C++, C#, Java, XQuery, XSLT 1.0, XSLT 2.0, XSLT 3.0.

 

Parameters

Name

Description

node

The node to be tested for existence.

 

Examples

The following mapping illustrates how to filter data with the help of exists function. This mapping is called PersonListsForAllBranchOffices.mfd and it can be found in the <Documents>\Altova\MapForce2021\MapForceExamples\ directory.

mf-func-exists-example-01

PersonListsForAllBranchOffices.mfd

In the source file BranchOffices.xml, there are three Office elements. Notably, one of the offices does not have any Contact child elements. The goal of the mapping is many-fold:

 

a) for each office, extract a list of contacts that exist in that office

b) for each office, create a separate XML file with the same name as the office

c) do not generate the XML file if the office has no contacts.

 

To achieve these goals, a filter was added to the mapping. The filter passes on to the target only those Office items where at least one Contact item exists. This Boolean condition is provided by the exists function. If the function's result is true, then the name of the office is concatenated with the string .xml in order to produce the target file name. For more information about generating file names from the mapping, see Processing Multiple Input or Output Files Dynamically .

 

Another example is the following mapping: <Documents>\Altova\MapForce2021\MapForceExamples\HasMarketingExpenses.mfd. Here, if an expense-item exists in the source XML, then the hasExpenses attribute is set to true in the target XML file.

mf-func-exists-example-02

HasMarketingExpenses.mfd

See also Example: Exception When Node Does Not Exist.

© 2015-2021 Altova GmbH