[CentOS] php DOMDocument and entities

Thu Sep 24 20:21:08 UTC 2015
Alice Wonder <alice at domblogger.net>

This is not CentOS specific but I hope someone here knows so I do not 
have to subscribe to another list.

I'm using php DOMDocument to create an XSL that needs a non-breaking 
space between two values.


$xslvalueof = $dom->createElement('xsl:value-of');
     $xslvalueof->setAttribute('select', '../@month');
$nbsp = $dom->createTextNode(' ');
$xslvalueof = $dom->createElement('xsl:value-of');
     $xslvalueof->setAttribute('select', '../@year');

That's what I am trying to do.

createTextNode() however tries to protect the users, and automatically 
turns any & into &

So I tried

$nbsp = $dom->createEntityReference('#160');

That however gives a dom error, it seems createEntityReference only 
works with named entities.

$nbsp = $dom->createEntityReference('nbsp');

works, but then I would have to modify the DTD for both XSL and the 
target XML because neither have nbsp defined.

How can I create the literal string ' ' using DOMDocument as a text 
node between two other nodes?

This is driving me nuts.

I could I suppose put it inside a span

&nbsp = $dom->createElement('span', ' ');

That works but is hackish. It seems to work though by generating the 
actual UTF8 character itself.

I really wish the XML spec itself had named entities for the various 
whitespace characters that tend to get eaten by XML parsers if not done 
as a numbered entity. Ah well.

Using   works just fine when the XSL is a text file. It is 
dynamically creating it via DOMDocument where I have a problem.

Thanks for any suggestions.

Sent my from my laptop, may not be able to respond timely