Check for positive and negative about in a XSL StyleSheet

abooysen2
abooysen2 used Ask the Experts™
on
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>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
yes, you can simply check

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

Open in new window

Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
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

Information Architect
Top Expert 2006
Commented:
this works in XSLT2.0 only

<xsl:value-of select="if (@Movement &lt; 0 ) then '-1.0' else '1.0'"/>
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Author

Commented:
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
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
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

Author

Commented:
i used <xsl:value-of select="if (@Movement &lt; 0 ) then '-1.0' else '1.0'"/> and it worked 100% thanks

Author

Commented:
i used <xsl:value-of select="if (@Movement &lt; 0 ) then '-1.0' else '1.0'"/> and it worked 100% thanks
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
so you are using XSLT2, good to know
cheers

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial