Jeni Tennison.
> Could somebody explain to my WHY '&' translates to '&' > but ' ' doesn't change at all?
Let's consider this simple stylesheet:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head><title>Test</title></head> <body> <p>Non-breaking&nbsp;space</p> <p>Non-breaking space</p> </body> </html> </xsl:template> </xsl:stylesheet>
This stylesheet is stored on the hard disk as a series of bytes. The bytes match characters according to the ISO-8859-1 encoding (see the encoding pseudo-attribute on the XML declaration?). When the XML parser reads in this as an XML document, it decodes the bytes into Unicode characters. It also parses the document, recognising things like start tags (e.g. <p>), built-in entity references (e.g. &) and character references (e.g.  ). The parser knows that & stands for an & character (because it knows XML) and knows that   stands for a non-breaking space character (because it knows XML and Unicode). The parser reports to the XSLT processor when elements occur and what characters text is made up of, but doesn't report whether a particular character was originally serialized as the plain character (an actual space character), an entity reference or a character reference. As far as an XSLT processor is concerned, therefore, the following elements in the stylesheet (or in an XML source document) would all be reported as *exactly* the same (a p element containing a text node whose string value is a double-quote character):
<p>"</p> <p>"</p> <p>"</p> <p>"</p> <p><![CDATA["]]></p>
The two p elements serialized in the stylesheet, look like:
<p>Non-breaking&nbsp;space</p> <p>Non-breaking space</p>
For the first p element, the XML parser reports the string (here containing no escaping of any kind - every character is a literal character): Non-breaking space For the second p element, the XML parser reports the string (here containing an underscore character as a stand-in for a non-breaking space, since you can't see non-breaking spaces in emails): Non-breaking_space The XSLT processor builds a result tree from the stylesheet, which contains these text n |