Solved

Format currency xslt

Posted on 2009-07-14
11
1,352 Views
Last Modified: 2013-11-18
I need to do 2 things
1. add the trialing zero to a price
I have tried this but it is having no affect
 <xsl:value-of select="format-number(yahoo:Price, '#,00')"/>

2 i need to prefix the price with £ but xsl doesnt like it, i have also tried &pound; but it doesnt like that either.

how can i prefix the price with £

Thank you
0
Comment
Question by:QuinnDester
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24853327
2.
&#163;
will give you no problem,

1.
Can you show the XML and say what exactly you want?
could be
<xsl:value-of select="format-number(yahoo:Price, '#.00')"/>
maybe it isn't numeric, because of the ',' in your source
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 24853393
found the error for 1. Gertone.
most are numeric but some have a string in them EG. not available.

how can i check its a numeric value and apply the formating accordingly
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 24853419
for number 2 i get this £11,79

the £ sign is there but i also have an A with a hat on :)
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24853443
a test for number could be
not(string(number(.)) = 'NaN')
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24853459
&#163;
should always result in a pound signe, without the Â
If you see the  in front of it, it means that some process thinks it is ISO-Latin 1 instead of UTF-8
but some process in between is in error,
how to you execute the XSLT?
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 24853489
at the moment i am using xmlspy, i havnt tried it in the application yet, ill give that a go now
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 24853577
Thanks Gertone, directly in the application it works fine, it must be an xmlspy thing

I have tried this to test for the number but i am shooting in the dark for the syntax, can you point out where i am going wrong.

            <xsl:choose>
      
            <xsl:when test="not(string(yahoo:DeliveryCost(.)) = 'NaN')">
                &#163;<xsl:value-of select="format-number(yahoo:DeliveryCost, '#.00')"/>
                </xsl:when>
                <xsl:otherwise>
                <xsl:value-of select="yahoo:DeliveryCost"/>
                </xsl:otherwise>
</xsl:choose>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24853578
XML Spy doing stupid things.. that is no surprise :-)
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 24853611
If I were you, I would wrap the pound sign in a xsl:text element
<xsl:text>&#163;</xsl:text>
you will get rid of possible erroneous white-space, if you do so

about your problem, the test should be
<xsl:when test="not(string(number(yahoo:DeliveryCost)) = 'NaN')">
0
 
LVL 3

Author Comment

by:QuinnDester
ID: 24853675
brilliant thank you Gertone

i tried this and it does work but doesnt recoginise 0 as a number,

<xsl:when test="number(yahoo:DeliveryCost)">

your way gets everything thank you

and i will start rapping text in <text></text> thank you for the advice
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24853691
welcome
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

615 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