Solved

[XSLT] How to add a non-breaking space to HTML output?

Posted on 2003-12-02
4
1,718 Views
Last Modified: 2008-03-06
Okay, simple problem. I have an XML file linked to an XSL file. The XML file will be opened in Internet Explorer 6 and this shoudl result in a client-side transformation of a small data file with a small transformation file into what would be a very large HTML page. The HTML output is quite big because of the use of colors, tables and lots of formatted fields. And because the internet connection and server are a bit slow while the clients are pretty fast, I need this client-side transformation. Fortunately, IE does this automatically.
However, there will also be some users who need the XML file to be translated server-side because they use either a different webbrowser or an older webbrowser that doesn't support XML. These users might not even have any Unicode support on their system.

However, my problem is that I need   tags in the HTML output too. If I just use   then IE will not transform my XML file but just report an error. I tried to use   but IE then generates   instead of the required blank space. I could use   and this seems to give the correct result but it's still not exactly what I need.
Sure, the HTML output will convert   to a NBSP but it generates it as a unicode character and not as the   tag. I can't allow the NBSP to be hardcoded in the output as an Unicode character because some people would just see ' ' in their output. Yes, a funny A followed by a space... So, for those users who need the pre-translated file I need to have   in my output file.

Now, how to do this with XSLT??? How to keep unicode out of my output file?
0
Comment
Question by:Wim ten Brink
  • 2
4 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 9857402
the xml for non-breaking space is   
i have never seen the problem as you describe. but you use " " maybe that makes the difference?
0
 
LVL 17

Author Comment

by:Wim ten Brink
ID: 9858056
The problem is quite simple, actually. I can't generate the &nnbsp; tag in any way by using XSLT... IE hates it when I use   in my xslt file since it considers it an illegal tag. And according to the XML standard IE is right too.   is not allowed. But I want either   or &30160; to be generated in my output, instead of the NBSP character. And that's my problem.
It is fun, btw. If I use & then the output will contain & instead of &. But when I use   the translator fails. In other words, it's not translated correctly. It just happens to be okay when the webbrowser can handle unicode characters...
0
 
LVL 9

Accepted Solution

by:
sparkplug earned 125 total points
ID: 9858770
Hi,

Make sure you have <xsl:output method="html"/> at the top of your XSLT (under the <xsl:stylesheet>) tag. You can then use &#160; or &#xA0; and these will be translated to &nbsp;

Alternatively you can use &nbsp; in your XSLT after putting <!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "&#160;">]> at the top of the file.

Another less elegant solution would be to use <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text> or <xsl:text disable-output-escaping="yes">&amp;#160;</xsl:text>.

For more info and explanations see this FAQ: http://www.dpawson.co.uk/xsl/sect2/nbsp.html

Hope this helps,

>S'Plug<
0
 
LVL 17

Author Comment

by:Wim ten Brink
ID: 9865744
I have to admit, <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text> isn't pretty but does the trick quite well. :) Thanks.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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, …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now