Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2006, 03:41 AM
Authorized User
 
Join Date: Jun 2006
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Default Trouble with poundsign (£)

Hi,

I have a web app with text boxes allowing the user to enter comments, which then is saved into the database and returned as xml.

Because of the nature of the app it is very common for users to enter poundsigns.

I am then transforming this using XSL into HTML to be put through a PDF generator.

The poundsigns seem ok in XML, seem to handle ok in XSL and render in HTML [u]BUT</u> they render as £ not &pound;

I have tried
Code:
<xsl:value-of select="translate($temp, '£', '&amp;pound;' )" />
which obviously doesn't work.

and i have tried
Code:
    <xsl:call-template name="replaceCharsInString">
        <xsl:with-param name="stringIn" select="." />
        <xsl:with-param name="charsIn" select="'£'" />
        <xsl:with-param name="charsOut" select="$PoundString" />
    </xsl:call-template>    


<xsl:template name="replaceCharsInString">
    <xsl:param name="stringIn" />
    <xsl:param name="charsIn" />
    <xsl:param name="charsOut" />
    <xsl:choose>
        <xsl:when test="contains($stringIn,$charsIn)">
            <xsl:value-of select="concat(substring-before($stringIn,$charsIn),$charsOut)" />
            <xsl:call-template name="replaceCharsInString">
                <xsl:with-param name="stringIn" select="substring-after($stringIn,$charsIn)" />
                <xsl:with-param name="charsIn" select="$charsIn" />
                <xsl:with-param name="charsOut" select="$charsOut" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$stringIn" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
Which also doesn't work

PLEASE HELP.. I'm on a tight deadline for this project to go live and at the moment we have question marks for poundsigns in our PDF..

Cheers

Darren

 
Old June 12th, 2006, 03:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It looks as if there's some problem with the downstream application that's processing your XML output. By default your output will be encoded in UTF-8, perhaps the downstream application isn't decoding it correctly.

See what happens if you do

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

or even

<xsl:output encoding="us-ascii"/>

The latter will force the character to be output as a character reference, for example &_#xa3; (without the underscore).

Note that &_pound; is recognized in HTML, but not in XML unless you declare it in your DTD.

There's little point, incidentally, in telling us your problem is urgent. In fact, I usually ignore posts marked as urgent because it often means the poster is panicking and won't take the time to think about the response before posting the next follow-up.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 12th, 2006, 04:20 AM
Authorized User
 
Join Date: Jun 2006
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Michael,

Thanks for the prompt reply (I was very impressed, I have your book sat at the side of me and it's been a huge help - Thanks)

But unfortunately I've tried changing the encoding already and still the HTML renders as £ instead of
Code:
&pound;
Oh also I forgot to mention before the PDF generator insists that the HTML for the poundsign must be
Code:
&pound;
, so I need to convert every instance of £ in a string with
Code:
&pound;
.

Cheers Again

Darren

 
Old June 12th, 2006, 04:58 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Oh also I forgot to mention before the PDF generator insists that the HTML for the poundsign must be
Code:
&pound;
, so I need to convert every instance of £ in a string with
Code:
&pound;
.

As I thought, a problem with the downstream application. It's got no business to make such a distinction.

What processor are you are using? You may be able to force output of &pound; using disable-output-escaping="yes". But it may be easier to post-process the generated HTML using a text editor or a Perl script.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 12th, 2006, 05:56 AM
Authorized User
 
Join Date: Jun 2006
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Default

>it may be easier to post-process the generated HTML using a text editor or a Perl script.

excellent Idea, the transform is done through VB.net, I can find and replace the £'s.

Brilliant

Thanks you...






Similar Threads
Thread Thread Starter Forum Replies Last Post
If Else Trouble Cibressus Beginning PHP 0 May 1st, 2007 02:04 PM
SQL Trouble mrideout BOOK: Beginning ASP.NET 1.0 1 September 30th, 2004 12:24 PM
Please i have had a Trouble hurted Wrox Book Feedback 1 June 28th, 2004 02:18 AM
trouble databass Classic ASP Databases 2 August 16th, 2003 10:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.