I have an XML processed by an XSLT, but Mozilla Firefox 24 ESR parses my XML correctly while Google Chrome 42 is failing to get the node from XML.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script>
var xslInput = "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"> <xsl:output method=\"xml\"/> <xsl:variable name=\"outcome\" select=\"F1- RetBOMs/selectBOM/results[2]/bom\"/><xsl:variable name=\"SINGLE_QUOTE\" select=\""'"\"/> <xsl:template match=\"/*\"> <result> <xsl:copy-of select=\"$outcome\"/> </result></xsl:template> </xsl:stylesheet>" ;
var xmlInput = "<root><F1-RetBOMs><selectBOM><results><bom>Value 1 for first block</bom><description>Description 1 for first block</description></results> <results><bom>Value 2 for second block</bom><description>Description 2 for second block</description></results><rowCount>2</rowCount></selectBOM></F1- RetBOMs></root>";
function createXMLDoc(xmlText){
var parser = new DOMParser();
if (xmlText) {
xmlDoc = parser.parseFromString(xmlText, 'text/xml');
} else {
xmlDoc = document.implementation.createDocument('', '', null);
}
return xmlDoc;
}
function convertXSL(){
var xmldoc = createXMLDoc(xmlInput);
var xsldoc = createXMLDoc(xslInput);
var oProcessor = new XSLTProcessor();
oProcessor.importStylesheet(xsldoc);
try{
var outputDoc = oProcessor.transformToDocument(xmldoc.documentElement, document);
}catch(e){
//console.log(e);
}
document.getElementById('result').innerHTML = new XMLSerializer().serializeToString(outputDoc);
}
</script>
</head>
<title></title>
<body>
<div id="result" style="min-height:300px; min-width: 400px; border: 1px solid blue"></div>
<span id="clickme" style="min-height:30px; min-width: 40px; border: 1px solid red" onclick="convertXSL()">Click Me</span>
</body>
</html>
I am trying to get <bom>Value 1 for first block</bom> from xmlInput through XSLT logic but when I am using
<xsl:copy-of select=\"$outcome\"/>
to get the outcome variable Chrome is not parsing through results tag and giving an empty tag in my result div. Same thing happens with Safari.
You can try the whole code in an HTML file and see different browser behavior.
Can anyone please tell me, what am I doing wrong? Is this related with some webkit behavior?