[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1048
  • Last Modified:

XSLT string comparison issue

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?

0
abemiester
Asked:
abemiester
  • 2
1 Solution
 
zc2Commented:
the processor converts the strings to numbers and gets NaN
when you compare two NaNs it will be always false:

Even
<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

0
 
abemiesterAuthor Commented:
Why is it converting them to numbers?  I thought it would do a string compare unless i specified otherwise...
0
 
zc2Commented:
it's by the W3 recommendation
http://www.w3.org/TR/xpath#booleans
(read the paragraph after the first NOTE)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now