Convert Negative to Positive

Here should go questions about transforming XML with XSLT and FOP.
FeelinGroovy
Posts: 2
Joined: Thu Jan 12, 2023 9:58 pm

Convert Negative to Positive

Post 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>
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Convert Negative to Positive

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
FeelinGroovy
Posts: 2
Joined: Thu Jan 12, 2023 9:58 pm

Re: Convert Negative to Positive

Post by FeelinGroovy »

Thanks for the reply. I will give this a try and will post the results.
Post Reply