It turns out webkit doesn't appear to behave particularly well with whitespace while processing an XSLT. It seems to treat newline, carriage returns, tabs and spaces equally, even to the point where substring-after('test string',' ')
will return string
.
Is there any way of getting it to behave properly, or is this a bug in webkit that doesn't have a workaround?
EDIT: Here's some javascript that demonstrates the error:
var parser = new DOMParser();
var xsltText = "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"version=\"1.0\"><xsl:template match=\"test\"><output><xsl:value-of select=\"string-length(substring-after(., ' '))\"/></output></xsl:template></xsl:stylesheet>";
var xslt = parser.parseFromString(xsltText, "text/xml");
var xmlText = "<test>test string</test>";
var xml = parser.parseFromString(xmlText, "text/xml");
var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xslt);
var processed = xsltProcessor.transformToDocument(xml);
var result = processed.firstChild.textContent;
The result
variable should obviously contain '0'; in Safari 4 and Chrome 8 it returns '6'.