Billy
Billy

Reputation: 2630

xslt 1.0 to HTML table spacing problem

All,

I am attempting to place spaces/indent text in a column in my HTML table. I am reading a XML file using XSLT 1.0 and writing it to a HTML file. I have tried the following:

<?xml version='1.0' encoding='utf-16'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes" encoding="utf-16"/>

<tr>
  <td/>
  <td>
    <xsl:text xml:space="preserve">&#160;</xsl:text>
    <xsl:value-of select="concat('Substantiation-', 
                    @sourceID, ' (', current(), ')')"/>
  </td>
</tr>

The results when viewed in Internet Explorer (opened from the generated html file) looks like:

 Substantiation-9010 (p 1-5, Para 1-10.)

I have also tryed &#x9;, &#x20;, and &#xa0; it has similar or no results.

I am assuming that I have an encoding issue (thanks to Michael Kay for pointing that out), however I'm not sure what I'm doing wrong since I am specifing the encoding in the output tag. Does anyone know how to either add space/tab so it looks correct when viewed in IE?

Thank you for your help!!!

Upvotes: 0

Views: 660

Answers (4)

Billy
Billy

Reputation: 2630

I couldn't get the spaces to show up correctly. Everything suggested here from what I read should have worked. However, it wasn't for me. I ended up using an image with a transparent background.

 <img src="OnePixel.gif" width="15" height="5" align="left"/>

Upvotes: 0

Michael Kay
Michael Kay

Reputation: 163262

Inserting an &#160; character is the right way to add a non-breaking space. But it's being displayed incorrectly because of some kind of encoding problem - you're generating a UTF-8 document but internet explorer thinks it's iso 8859-1 (or MS CP1252). The reasons IE gets the encoding wrong are myriad (and beyond my comprehension), but you haven't started to give us the information needed to diagnose them (we don't even know if this transformation is server-side or client-side).

(Of course, other responders are right that there might be better ways to achieve the required layout than to use NBSP characters. But if you've got an encoding problem, it will affect other characters too, so you shouldn't leave it festering.)

Upvotes: 5

walkingTarget
walkingTarget

Reputation: 408

&nbsp; is the non-breaking space special HTML character. Give that a whirl. Alternatively, try using CSS to create padding within the Table Cell. Even more alternatively, if you are creating a list, try using <ol> or <ul>.

Upvotes: 0

ChaosPandion
ChaosPandion

Reputation: 78242

You can use CSS to resolve this problem:

<tr>
  <td/>
  <td>
      <span style="white-space:pre;">&#9;<xsl:value-of select="concat('Substantiation-',@sourceID, ' (', current(), ')')"/></span>
  </td>
</tr>

Upvotes: 0

Related Questions