XSLT string comparison issue

Posted on 2008-11-12
Last Modified: 2013-11-18
every time i do this comparison in my transform:
<xsl:value-of select="'$300,000.00' &gt; '$155,000.00'" />
it returns false.  Seems to me that it should return true.  What am i missing here?

Question by:abemiester
    LVL 18

    Accepted Solution

    the processor converts the strings to numbers and gets NaN
    when you compare two NaNs it will be always false:

    <xsl:value-of select="number('s') = number('s')" />
    returns false.

    To correctly compare the strings as numbers you need to strip all invalid characters:
    <xsl:value-of select="number(translate('$300,000.00','$,','')) &gt; number(translate('$155,000.00','$,',''))" />

    Open in new window


    Author Comment

    Why is it converting them to numbers?  I thought it would do a string compare unless i specified otherwise...
    LVL 18

    Expert Comment

    it's by the W3 recommendation
    (read the paragraph after the first NOTE)

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    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.
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now