26

I have written one XSLT to transform xml to html. If input xml node contains only space then it inserts the space using following code.

<xsl:text>&#xa0;</xsl:text>

There is another numeric character which also does same thing as shown below.

<xsl:text>&#160;</xsl:text>

Is there any difference between these characters? Are there any examples where one of these will work and other will not?

Which one is recommended to add space?

Thanks,
Sambhaji

kapa
  • 77,694
  • 21
  • 158
  • 175
Sambhaji
  • 990
  • 5
  • 19
  • 31

2 Answers2

42

&#160; is a non-breaking space (&nbsp;).

&#xa0; is just the same, but in hexadecimal (in HTML entities, the x character shows that a hexadecimal number is coming). There is basically no difference, A0 and 160 are the same numbers in a different base.

You should decide whether you really need a non-breaking space, or a simple space would suffice.

kapa
  • 77,694
  • 21
  • 158
  • 175
  • So there is no difference between   and  ? – Black Nov 28 '18 at 12:41
  • 3
    Nope, not at all – kapa Dec 12 '18 at 12:04
  • I just a weird error in PHP due to the difference between ` ` and ` `. There was an space (" " not " ", encoded differently I guess) in an `if` block, causing from undefined variables to syntax errors. I noticed it thanks to VSCode when I rewrote the `if` statement and `Ctrl` + `D` didn't match the other line even though it was the same content. – Mithc Jan 16 '20 at 22:37
13

It's the same. It's a numeric character reference. A0 is the same number as 160. The first is in base 16 (hexadecimal) and the second is in base 10 (decimal, everyday base).

Xavi López
  • 27,550
  • 11
  • 97
  • 161