Solved

How to display a Euro symbol in XSL?

Posted on 2004-04-19
11
3,119 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net and XML XSD Files 1 61
XML filtering Windows Event Viewer 10 61
Convert XML to excel12book 5 31
C# Formatting DateTime String Value 5 27
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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, …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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