UPDATE: If the value does not begin with a "-" sign, the below logic has a flaw and does not work. Updated example below.
Using your payload as the example,
1) When the request comes into the VSM, DevTest attempts to parse out the XML and convert the elements into key/value pairs.
2) These converted elements are used in the VSI to evaluate the request. They can also become candidates for Magic String processing which marshals data from the input request into the response.
3) DevTest creates properties by iterating over the XML document. The resulting property names end up following a pattern where the key side of the K/V pair is a concatenation of its respective parent element names. Further, DevTest places its own internal "request_" value in front of the property name to provide some ease of access. Using the below XML request data as an example, coupled with a REST DPH and an XML Data Protocol DPH:
POST /user/sample/amounts HTTP/1.1
<payload>
<Bill>
<Amount>-17.2</Amount>
</Bill>
</payload>
The resulting VSI contains a transaction that looks like this:
Notice that the 'Bill_Amount' key represents this element's position in the DOM. Instances where amount is part of list will result in DevTest post fixing a value of 1 to n so that each K/V pair remains unique.
4) DevTest utilizes the Magic String concept to move the Bill_Amount from the incoming request into the response to make the transaction as 'real' as possible. This is implemented using {{ }} notation having a reference to the incoming element name. For example, to magic string the value as-is including the '-' sign:
5) Your scenario has to go a step further in that your requirement is to remove the '-' sign from the amount. To do this, we can use some BeanShell scripting and add a small amount of code to implement the behavior to remove the '-' sign.
The code that is added to the response is as follows:
<payload>
<BillGenerated>
<RequestAmount>{{=request_Bill_Amount;/*-17.2*/}}</RequestAmount>
<AmountDeducted>{{=if ("-".equals( testExec.getStateValue("request_Bill_Amount").substring(0, 1) ) ) return testExec.getStateValue("request_Bill_Amount").substring(1); else return testExec.getStateValue("request_Bill_Amount")}}</AmountDeducted>
</BillGenerated>
</payload>
So, using the R/R pair with a REST call to the service yields the following:
In this example, the META transaction is configured to handle the response using the Magic String logic, so when the incoming bill amount changes, so does the response output:
Using updated script to cater for no "-" sign on input request: