[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

xsl: display absolute value of abc

Posted on 2007-08-07
3
Medium Priority
?
1,690 Views
Last Modified: 2013-11-18
i am using the following:

<xsl:value-of select="abc" />

the value of abc can be negative. how do i display absolute value of abc.

thanks.
0
Comment
Question by:jgordin
  • 3
3 Comments
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 2000 total points
ID: 19649705
       <xsl:choose>
            <xsl:when test="abc &lt; 0">
                <xsl:value-of select="abc * -1"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="abc"/>
            </xsl:otherwise>
        </xsl:choose>
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 19649722
If you can use XSLT2, there is an abs() function
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:template match="/">
        <xsl:value-of select="abs(abc)"></xsl:value-of>
    </xsl:template>
</xsl:stylesheet>

cheers

Geert
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 2000 total points
ID: 19649748
Here is the way I prefer to do this in XSLT1,
It is a lot simpler than the choose, but it is a bit more obscure

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:value-of select="abc * (1 - 2 * (abc &lt; 0))"></xsl:value-of>
    </xsl:template>
</xsl:stylesheet>

It relies on the fact that if a boolean is casted to a number, true = 1 and false = 0

Now the bag of thricks is empty, unless you want an extension function
and use the abs() of java or javascript.... but I don't recommend that

cheers

Geert
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question