Forum Moderators: open

Message Too Old, No Replies

XSLT and the dreaded non-breaking space

should you really use  ?

         

joshie76

12:06 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wasn't sure where to post this as there isn't an obvious home for XSLT questions (that I can't find) so I chose here as it's the home of Xoc who seems fairly clued up on such matters...

Until today we where happily using   as a replacement for the   in all our XSLTs, that is until a client in china tried to view the output and got a mangled mess of bizarre characters. Some research led us to find that no ASCII character higher than 127 should be used in an HTML document so that's   out the window (which XSLT outputs as an ASCII character (160) that looks like a normal space but behaves like an   ).

So we tried using the following:

<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>

Which worked a treat until it was thrown through one of our display templates. Our display templates kind of act like a picture frame and uses copy of to draw out the picture (some HTML passed as a parameter):

eg:

<xsl:template name="pictureframe"> 
<xsl:param name="title"/>
<xsl:param name="html"/>
<table>
<tr>
<td><xsl:copy-of select="$title"/></td>
</tr>
<tr>
<td>
<xsl:copy-of select="$html"/></td>
</td>
</tr>
</table>
</xsl:template>

<xsl:call-template name="pictureframe">
<xsl:with-param name="title">
<b>Title</b>
</xsl:with-param>
<xsl:with-param name="html">
<b>This</b> is the content!
</xsl:with-param>
</xsl:call-template>

The real template is a bit more complicated but we've found this a great way of creating re-usable html templates. Our previous &nbsp; (from

<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
) now outputs &amp;nbsp; to the HTML. Very frustrating!

We've tried every possible combination of output-escaping on or off and more, even <![CDATA[]]> section seem to have no effect.

Any ideas? Please help!

Xoc

2:14 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Which XML parser are you using? I've run into similar problems with the MSXML parser and have been unable to resolve it. I get the same results, either a non-breaking space in the output or & a m p ; n b s p ; in the output, but not the correct result with & n b s p ; in the output (spaces removed). Except that I was using another character, 187 instead of 160.

I spent a number of hours banging my head against this one and never did find the solution. So you aren't alone here. If you do find a solution, I really would like to hear it.

korkus2000

2:19 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Same here. I have never found a solution. I tried to get an answer through msdn and your work arounds are what they gave me. I have spent weeks on this problem and never found an answer.

joshie76

2:22 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Tried in both MSXML 3 & 4.

It's both pleasing and disappointing at the same time to find I'm not going nuts on this one! I'll be sure to report in if I ever solve it.

The whole thing has got me thinking though....

When the output method is set to html then an &amp; inside <script> tags does pop out as an & (as required). However, what do you do when you want to create an xhtml document?

I'm guessing the output method should be xml (as xhtml is not a valid option), but then the &amp; would appear as an &amp; inside script tags and therefore you'd be unable to use the && operator in JavaScript.