Go Premium for a chance to win a PS4. Enter to Win

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

How to display a Euro symbol in XSL?

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
julescantwell
Asked:
julescantwell
  • 4
  • 4
  • 2
  • +1
2 Solutions
 
rdcproCommented:
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
 
julescantwellAuthor Commented:
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
 
dualsoulCommented:
><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
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!

 
rdcproCommented:
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
 
julescantwellAuthor Commented:
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
 
rdcproCommented:
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
 
julescantwellAuthor Commented:
Thanks Mike-
I made that change, but still no luck!
0
 
Yury_DelendikCommented:
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
 
rdcproCommented:
I'm pretty sure that &#8364; is the ISO-8859-1 character reference for the euro symbol.

Regards,
Mike Sharp

0
 
julescantwellAuthor Commented:
I changed the encoding to utf-16 and the euro symbol displays correctly.
0
 
dualsoulCommented:
windows-1251
oh yeah :) it will be much better of Anglo-lingual people ;))
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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