Mapping Negative Numbers

Situation:

Is there an easy way to convert a number that may have a trailing negative sign from my source to one in a standard format? For example, my source data shows 870.00- which must be converted to -870.00 in order to be inserted into a database.

Below is my resulting XSL, but this seems far more complicated than it should need to be.

    <PAYMENT_AMOUNT>
    <xsl:choose>
    <xsl:when test="substring(column4 , string-length(column4 ) , string-length(column4 ) ) = &apos;-&apos;">
    <xsl:value-of select="concat(&apos;-&apos; , substring(column4 ,0 , string-length(column4 ) ) )"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="column4"/>
    </xsl:otherwise>
    </xsl:choose>
    </PAYMENT_AMOUNT>

 

Solution:

Please use the XSL below to map a negative number :

<Amount>
<xsl:choose>
<xsl:when test="contains( Amount,&apos;-&apos; ) = &apos;true&apos;">
<xsl:value-of select="normalize-space( concat(&apos;-&apos; , translate(Amount ,&apos;-&apos; ,&apos;&apos; ) ) )"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="Amount"/>
</xsl:otherwise>
</xsl:choose>
</Amount>
Have more questions? Submit a request

0 Comments

Article is closed for comments.