How to display special characters in XSL

G

Gaizka

Hi,

I have a XML file which looks like this.

<article_content id="364098" status="A">
<title>Weekly Sector Review</title>
<date>20041008</date>
<time>09:11:00</time>
<body>BP’s third quarter figures were well received with
investors cheering the prospect of enormous profits this year and
possibly more to come with oil prices remaining stubbornly high.
<introduction>Weekly review of the biggest sector
movers</introduction>
<category_id>0100</category_id>
</article_content>

How can make so that the XSL will display the character ’ as '
in the HTML page?

Thanks a lot

GA
 
A

Andy Dingley

How can make so that the XSL will display the character ’ as '
in the HTML page?

XSL doesn't "display" things, it just makes another output document,
typically as either HTML or XML. It's default behaviour will be to
generate ’ in the output, exactly as for the input. For HTML,
this is perfectly adequate - ’ is valid,

In some obscure cases (I was bitten by this with Vodafone's
PaertnerML) ’ isn't acceptable. I had to whack it with some
JavaScript and a regex.
 
G

Gaizka

Andy Dingley said:
XSL doesn't "display" things, it just makes another output document,
typically as either HTML or XML. It's default behaviour will be to
generate ’ in the output, exactly as for the input. For HTML,
this is perfectly adequate - ’ is valid,

ok the character in the XML file is &#8217 and I need transform it to
' in the HTML file

In some obscure cases (I was bitten by this with Vodafone's
PaertnerML) ’ isn't acceptable. I had to whack it with some
JavaScript and a regex.


Any other option than replacing it? :(

thanks

GA
 
A

Andy Dingley

ok the character in the XML file is &#8217 and I need transform it to
' in the HTML file

Why ? Is it really not working ? - this entity ought to be perfectly
valid and workable in all cases, as a substitute for the character.

You can't really control this in XML. It's part of the fundamentals of
XML that the two representations are interchangeable, and so you don't
have control over it. If you wanted to, you would have to either
re-write or replace the XML serialiser that generates your output
document.

If you change the XSL output mode to text (or possibly HTML) then the
serialiser _may_ stop generating the entity, although this is platform
dependent.


You might find that you need to convert the "curly quote" to a
"straight quote". This is rare, but as mentioned, it does sometimes
arise.

If you want to substitute it, the XSL string function "translate()"
should be able to help. Or else you can use a piece of JavaScript and
a regex. Place either in a named template rule and pass them the
text() content of the affected elements.
 
D

David Carlisle

ok the character in the XML file is &#8217 and I need transform it to
' in the HTML file

You mean you need a real ascii ' in the file or just that you want it to
display as that?
As others have said, & #8217; should just work. Apart form anything
else, if you are generating HTML I would expect most XSLT engines to
output it as & rsquo; as they usually use html entities where possible.

If you need to generate an ascii ' then you can use translate as in
<xsl:value-of select="translate(.,'& #8217;',&quot;'&quot;)"/>

(without the space after the &) to replace any right quote characters in
the current element content.

David
 
G

Gaizka

Hi again and thanks for helpng this xml/xsl dummy :)

The XML feed contains &#8217 characters

i found out that, after the trasformation, n my tomcat development I see ' ... :)
In the production server I still see &#8217, and also ? instead of £ ... :(

is it Tomcat default encoding xml the difference?

many thanks

GA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top