Solved

How to display a Euro symbol in XSL?

Posted on 2004-04-19
11
3,141 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
[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
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET reading ATOM 2 74
Formatting issues in XSL FO 3 50
TSQL query to generate xml 4 55
Help with a Python script converting xml to csv 4 44
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…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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