Liquid XML Studio
See Also Send Feedback
Data Mapping > Data Mapper Functions > By Category > Maths > Modulus

Glossary Item Box

Function Name
Return modulus (remainder) of a division calculation
Dividend Value to divide
Divisor Value to divide by
Result Remainder after dividing first input by second
None -


The Data Mapper Maths Modulus function allows you to calculate remainders after division on input values. You can use the Modulus function with input source data or in conjunction with other arithmetic functions in the Maths section. To apply the Maths Modulus function, use the following process:

Create a new Data Mapper file, dragging your XML data source and targets into the editor area. For this example we are using bookclub_source.xsd, an XML Schema Definition inferred from the following source:

Source XML Copy Code

For our target schema we will be using bookclub_target.xsd, inferred from the following XML:

Target XML Copy Code
 <section ref="14" joined="27">
 <section ref="7" joined="35">
 <section ref="15" joined="18">

The data models the members and books for a book club. Each group within the club has a certain number of books to share between the members. As you can see from the target data, as well as mapping the source data values, we need to include an indicator of how many books we can allocate to each member, plus a figure representing how many are left over - we will use the modulus to calculate this. Here is the Data Mapper with Source and Target imported:

Data Mapper Source and Target

Drag the Maths Modulus function from the Component Palette into the mapping area:

Modulus Component

Modulus Added

The Modulus component has two inputs, representing the value to divide and the value to divide it with. The output represents the remainder following this division operation. Both inputs and output of the Modulus function may be connected to items in the XML Reader/ Writer or other components in the Mapper.

Connect the Dividend input in the Modulus function to the "books" output in the XML Reader and the divisor input to the "members" output.

Reader to Modulus

Now connect the Modulus output to the "volumes_left" input in the XML Reader.

Modulus Function Mapped

That's the remainder part of the calculation completed, but we also need to indicate how many books there are per person, so drag a Divide function onto the Mapper. As with the Modulus function, connect the Dividend input to the "books" output in the XML Reader and the Divisor input to the "members" output.

Reader to Divide

Now, we need the number of books per person to be a whole number, so let's cast the division result to an integer. Drag a Cast function from the Type section onto the Mapper. Right-click it and choose Show Properties. Choose an integer type from the drop-down list.

Cast Properties

Now connect the Cast input to the Divide function output.

Cast Added

Now we can connect the Cast output to the "volumes_each" input in the XML Writer.

Cast to Writer

Finally let's make the remaining input and output connections. Remember to map "members" to "joined" - although we have used the members value for our division and modulus calculations, we have not yet mapped them to the output.

Inputs and Outputs Connected

We can now execute the transform by pressing Shift-F5 or the Execute button (Execute). The transform is applied and the file we selected as output opens in the editor:

Output XML Copy Code
 <section ref="12" joined="17">
 <section ref="10" joined="12">
 <section ref="5" joined="30">

The output contains an indicator of how many books can be allocated to each member in a group / section as well as how many are left over in each case.

This is a scalar function so the standard rules apply if multiple values are presented to one or more inputs.

See Also