Link to home
Start Free TrialLog in
Avatar of abooysen2
abooysen2Flag for South Africa

asked on

Check for positive and negative about in a XSL StyleSheet

Hi

I have a xml that I am Transforming but one element is an amount field that contains positive's and negatives. I want to know how can I check for positive's and negatives in a XSL StyleSheet

here is my xml
<?xml version="1.0" encoding="utf-8"?><transferupload><transfer><Currency>USD</Currency><LegalEntity>xxxx</LegalEntity><Accountid>1020</Accountid><Movement>-111390.73</Movement><ValueDate>2011-05-16</ValueDate><Narration>CFC Transaction 1300192643504</Narration><Counterparty>xx TREASURY</Counterparty></transfer></transferupload>

<?xml version="1.0" encoding="utf-8"?><transferupload><transfer><Currency>USD</Currency><LegalEntity>XXX</LegalEntity><Accountid>1020</Accountid><Movement>111390.73</Movement><ValueDate>2011-05-16</ValueDate><Narration>CFC Transaction 1300192643504</Narration><Counterparty>XXXXX TREASURY</Counterparty></transfer></transferupload>

Here is my XSL StyleSheet to get my Movement element
                                    <calypso:principal>
                                          <xsl:value-of select="transferupload/transfer/Movement"/>
                                    </calypso:principal>

Now I can to check in element quantity for positive amounts and negatives abouts
                  <calypso:quantity>
                              <xsl:value-of select="if (@Movement < ) then '-1.0'
                                    else '1.0'"/>
                        </calypso:quantity>
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

yes, you can simply check

<xsl:if test="@Movement &lt; 0">
   <xsl:text>-1.0</xsl:text>
</xsl:if>

Open in new window

or use choose


<xsl:choose>
 <xsl:when test="@Movement &lt; 0">
   <xsl:text>-1.0</xsl:text> 
 </xsl:when>
 <xsl:otherwise>
   <xsl:text>1.0</xsl:text>
 </xsl:otherwise>
</xsl:choose>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abooysen2

ASKER

so

<xsl:if test="@Movement &lt; 0">
   <xsl:text>-1.0</xsl:text>
</xsl:if>

means if I have a positive amount it will be 1.0
and
means if I have a negative amount it will be -1.0
no, it just sets the output entry to -1.0 if @Movement is smaller than 0
if you need what you just subscribe, you will need the choose construct
i used <xsl:value-of select="if (@Movement &lt; 0 ) then '-1.0' else '1.0'"/> and it worked 100% thanks
i used <xsl:value-of select="if (@Movement &lt; 0 ) then '-1.0' else '1.0'"/> and it worked 100% thanks
so you are using XSLT2, good to know
cheers