Solved

How to display a Euro symbol in XSL?

Posted on 2004-04-19
11
3,053 Views
Last Modified: 2008-02-01
Hi-
How do you display a Euro symbol in XSL? I've using ASP.NET with C# to get data from a database and perform an XSL transformation on it.

I have used both the &-e-u-r-o-; and &-#-8-3-6-4; special characters(hyphenated to avoid them displaying as actual euro symbols). When I hard-code these special characters, they display as euro symbols, but when I add them to XSL they display as '?'


Here is my XSLT file:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xsl:template match="/">
       <xsl:for-each select="NewsStoriesXML">
     
            
                  <!-- This is the MAIN CENTRAL CELL. It contains the Information specific to this page -->
                  <div align="center">
                        <table cellPadding="8" width="90%" border="0">
                              <tr>
                                    <td><p align="center" class="Headline3">News</p>
                                          <br/>
                                          <br/>
                                          <xsl:for-each select="NewsStories">
                       
                                                
                              
                                                <xsl:if test="storyType  = &quot;Upcoming Event&quot;">
                                                      <!-- Display Upcoming Event Table -->
                                                      <table width="100%" border="0">
                                                            
                                                            <tr class="NewsItemSubDetails" vAlign="top">
                                                                              
                                                                              <td  align="center" vAlign="center">
                                                                                    <br/>Admission:&#160;
                                                                                    <span class="NewsItemSubDetailsBold">
                                                                                          &#8364;<xsl:for-each select="price">
                                                                                                <xsl:apply-templates />
                                                                                          </xsl:for-each>
                                                                                    </span>
                                                                              </td>
                                                                  
                                                            </tr>
                                                            
                                                      </table>
                                                      
                                                </xsl:if>
                       
                       
                       
                                          <!-- All NewsStories added above -->  
                                          </xsl:for-each>
                                    </td>
                              </tr>
                        </table>
                  </div>
                   
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>


Thanks
0
Comment
Question by:julescantwell
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 26

Expert Comment

by:rdcpro
ID: 10861624
Are  you transforming to a stream?  Transforming to a string, then writing the string might be changing your encoding.  Your XSLT does not specify an encoding, either, so adding the xsl:output statement might help.  If you specify, say, UTF-8, but your transform is producing UTF-16, you'll have this problem as well.

<xsl:output method="html" encoding="utf-16"/>
or even possibly just:
<xsl:output method="html"/>

would help.  I've found that encoding problems can be tough to handle.  If your page uses one encoding, and your transform switches it, you'll have this problem too.  If the XSLT was outputting the <html> and <head> tags, the processor would probably have inserted the proper meta tag to tell the browser what encoding is being used.

Can you post the C# you're using for the transform?  Also, what encoding is the rest of the response written in?

Regards,
Mike Sharp
0
 

Author Comment

by:julescantwell
ID: 10861772
Hi Mike-


I had this at the top of the xsl file, but took it out and it was the same result both ways:
<?xml version="1.0" encoding="UTF-8"?>

here is the page directive of the c# page:
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>

This is the C# code, it writes the transformation to a string (as it only makes up part of the page)

public void DisplayUpcomingEvent()
            {
                  XmlDataDocument xmlDoc = new XmlDataDocument(ds);      
 
                  try
                  {
                        
                        
                        XslTransform xslTran = new XslTransform();

                        //should cache this file
                        xslTran.Load(Server.MapPath("xml/UpcomingEvent.xslt"));

                        //xslTran.Transform(xmlDoc, null, Response.OutputStream, null);
                        //Transform XML to HTML
                        MemoryStream ms = new MemoryStream();
                        xslTran.Transform( xmlDoc, null, ms, null );
                        ms.Seek( 0, SeekOrigin.Begin );

                        StreamReader sr = new StreamReader(ms);

                        //Insert result in the View.aspx page
                        string html = sr.ReadToEnd();

                        NewsItemLabel.Text = html;
                  }
                  catch (Exception ex)
                  {
                        Trace.Write(ex.Message);
                  }
            }
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 10862961
><xsl:output method="html" encoding="utf-16"/>
>or even possibly just:
><xsl:output method="html"/>

hm...with output=html euro sign outputs correctly, but IE doesn't show it properly...don't know why.
0
 
LVL 26

Assisted Solution

by:rdcpro
rdcpro earned 125 total points
ID: 10864071
Yes, you're probably having an encoding switch during the transform.  The page is encoded ISO-8859-1, but the result of your transform is probably UTF-8.  when you see this:

<?xml version="1.0" encoding="UTF-8"?>

it simply means that the source of the XSLT is encoded UTF-8.  The output encoding is specified in the xsl:output statement.  Use:

<xsl:output method="html" encoding="iso-8859-1"/>

along with:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>

Regards,
Mike Sharp
0
 

Author Comment

by:julescantwell
ID: 10868965
I have changed the reponse type of the XSL  by adding the xsl:ouput tag as indicated.
The page directive of the C# page is now: <%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>

However, the euro symbol is still displayed as '?'.  I stepped through the code with the debugger and found that in the string containing the result of the xsl transformation, it is also a '?'...whereas I had previously thought that the xslt was returning a correct euro symbol, and then the conflicting encoding of the C# page was altering it....it seems that the problem starts in the xslt?

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xsl:output method="html" encoding="iso-8859-1"/>
      <xsl:template match="/">
       <xsl:for-each select="NewsStoriesXML">
     
            
                  <!-- This is the MAIN CENTRAL CELL. It contains the Information specific to this page -->
                  <div align="center">
                        <table cellPadding="8" width="90%" border="0">
                              <tr>
                                    <td><p align="center" class="Headline3">News</p>
                                          <br/>
                                          <br/>
                                          <xsl:for-each select="NewsStories">
                       
                                                
                              
                                                <xsl:if test="storyType  = &quot;Upcoming Event&quot;">
                                                      <!-- Display Upcoming Event Table -->
                                                      <table width="100%" border="0">
                                                            
                                                            <tr class="NewsItemSubDetails" vAlign="top">
                                                                              
                                                                              <td  align="center" vAlign="center">
                                                                                    <br/>Admission:&#160;
                                                                                    <span class="NewsItemSubDetailsBold">
                                                                                          &#8364;<xsl:for-each select="price">
                                                                                                <xsl:apply-templates />
                                                                                          </xsl:for-each>
                                                                                    </span>
                                                                              </td>
                                                                  
                                                            </tr>
                                                            
                                                      </table>
                                                      
                                                </xsl:if>
                       
                       
                       
                                          <!-- All NewsStories added above -->  
                                          </xsl:for-each>
                                    </td>
                              </tr>
                        </table>
                  </div>
                   
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 26

Expert Comment

by:rdcpro
ID: 10870452
Oh, I didn't notice before, but &#8364; is the numeric character code in ISO-8859-1 for the euro.  Your XSLT specifies UTF-8 input encoding.  Try changing you XSLT declaration to:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet ...



Regards,
Mike Sharp
0
 

Author Comment

by:julescantwell
ID: 10870505
Thanks Mike-
I made that change, but still no luck!
0
 
LVL 10

Accepted Solution

by:
Yury_Delendik earned 125 total points
ID: 10874225
Hmmm...
You first code worked correct. Problem ISO-8859-1 doesn't contain euro symbol. It's better to change encoding to windows-1251 or utf-16
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 10879856
I'm pretty sure that &#8364; is the ISO-8859-1 character reference for the euro symbol.

Regards,
Mike Sharp

0
 

Author Comment

by:julescantwell
ID: 10883515
I changed the encoding to utf-16 and the euro symbol displays correctly.
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 10886772
windows-1251
oh yeah :) it will be much better of Anglo-lingual people ;))
0

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

13 Experts available now in Live!

Get 1:1 Help Now