Mashup Macro - Add/Subtract/Multiply/Divide
This is a basic mashup macro that let's the user use a mathematical operator (add, subtract, multiply, divide) between a selected field from 2 mashup inputs.
The example below shows multiply. Modify the operator in this line for add, subtract, or divide: 'array[count][nodeName] = array[count][lhsVar] * array[count][rhsVar];'.
<macro name="Multiply">
<input name="xmldoc" type="document" />
<presto-meta name="macrotype">user</presto-meta>
<input name="lhs" type="string" default="" />
<presto-meta name="type" variable="lhs" reference="xmldoc">datapath</presto-meta>
<presto-meta name="label" variable="lhs">Field 1</presto-meta>
<input name="rhs" type="string" default="" />
<presto-meta name="type" variable="rhs" reference="xmldoc">datapath</presto-meta>
<presto-meta name="label" variable="rhs">Field 2</presto-meta>
<input name="nodeName" type="string" default="Result" />
<output name="result" type="document" />
<variable name="repeatingElement" type="string" default="" />
<namespaces>
<namespace prefix="presto" uri="java:com.jackbe.jbp.jems.client.EMMLPrestoFunctions" />
</namespaces>
<assign outputvariable="repeatingElement" fromexpr="presto:infergroupXPath($xmldoc)" />
<if condition="$repeatingElement != '' ">
<script type="">
<![CDATA[
var array;
var re = repeatingElement.substring(repeatingElement.lastIndexOf("/*:")+3);
eval('array = xmldoc..*::' + re);
var count = 0;
var lhsVar = lhs.substring(lhs.lastIndexOf("/*:")+3);
var rhsVar = rhs.substring(rhs.lastIndexOf("/*:")+3);
for each(var record in array){
if(array[count].name().uri){
default xml namespace = array[count].name().uri;
}
array[count][nodeName] = array[count][lhsVar] * array[count][rhsVar];
count++;
}
result = xmldoc;
]]>
</script>
<else>
<assign fromvar="xmldoc" outputvariable="result" />
</else>
</if>
</macro>
(1 vote)
Groups:
- Login or register to post comments
- Email this page













