Is there any way of getting webkit's javascrip

2019-03-01 15:52发布

问题:

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(., '&#10;'))\"/></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'.

回答1:

I can't reproduce that problem with Safari 5.0.3. Test case (XML document loaded in browser window):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test2011012801Xsl.xml"?>
<test>foo bar</test>

where the stylesheet is

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:template match="/">
    <html>
      <head>
        <title>Test</title>
      </head>
      <body>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="test">
    <p><xsl:value-of select="string-length(substring-after(., '&#10;'))"/></p>
  </xsl:template>

</xsl:stylesheet>

Output in both Firefox (3.6) and Safari on Windows is "0". So at least with that test there is no evidence that a space character in a text node is treated as a newline character.