Page 1 of 1

Convert Negative to Positive

Posted: Thu Jan 12, 2023 10:16 pm
by FeelinGroovy
Hello all,
Using XSLT to translate an incoming cXML OrderRequest transaction to an outgoing proprietary format for B to B eprocurement purchasing flow. My scenario is as follows. Any suggestions would be appreciated. Thanks!

In the incoming cXML OrderRequest we have a dollar amount being passed to us as a negative value:
<ItemFees>
<Fee>
<Type>Commission</Type>
<Amount currency="USD">-4.11</Amount>
</Fee>
</ItemFees>

I am mapping to that fee and passing it in the outgoing format in an Extrinsic line:
<Extrinsic name="54">-4.11</Extrinsic>

What I need to do is convert the negative value to a positive value by simply removing the dash "-" before the dollar amount. I've tried several things but can't get it to work.

My current XSLT config is as follows. Anyone know if there is a way in this command structure to remove that dash, or tell it to convert it to a positive value?
<Extrinsic name="54">
<xsl:value-of select="OrderReport/Item/ItemFees/Fee/Amount"/>
</Extrinsic>

Re: Convert Negative to Positive

Posted: Fri Jan 13, 2023 9:28 am
by Radu
Hi,

Maybe you can convert the text value to an xs:float and then add a minus before that:

Code: Select all

<xsl:variable name="val" select="-xs:float(text())" as="xs:float" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
Regards,
Radu

Re: Convert Negative to Positive

Posted: Wed Jan 18, 2023 7:46 pm
by FeelinGroovy
Thanks for the reply. I will give this a try and will post the results.