Reputation: 2046
When applying the XSLT to XML file listed below no match is ever found. This transform is being preformed client-side in Internet Explorer 8 using the Msxml2 library. While my ultimate application is far more complex, the simple test below fails.
XML:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE document SYSTEM 'xmlschemas/domino_8_5_3.dtd'>
<document xmlns='http://www.lotus.com/dxl' version='8.5' maintenanceversion='3.0'
replicaid='862570A600460D8C' form='Appeal'>
<item name="criteria"></item>
</document>
XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dxl="http://www.lotus.com/dxl" >
<xsl:template match="dxl:document">
<xsl:text>It worked!</xsl:text>
</xsl:template>
</xsl:stylesheet>
I've read countless 'solutions' about name spaces and tried them all... it always fails to match. In a couple scenarios I was able to get the whole document by removing the !DOCTYPE tag, but the matching did then not work (just returned all text and never showed "It worked!"
EDIT: The same code which does the transform works in another part of my application, but not in this case. Here's the code:
var xml2;
var xsl2;
$.get("test2.xml", function(data) { getXSL(data); });
function getXSL(data) {
xml2 = new ActiveXObject("Msxml2.DOMDocument.6.0")
xml2.loadXML(data);
$.get("test2.xsl", function(data) { transformCriteriaXML(data); });
}
function transformCriteriaXML(data) {
xsl2 = new ActiveXObject("Msxml2.DOMDocument.6.0")
xsl2.loadXML(data);
var outFile;
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
outFile = "output.txt";
var objFile = objFSO.CreateTextFile(outFile, true);
objFile.Write(xml2.transformNode(xsl2));
objFile.Close();
}
Different operating systems and different IE versions are non-negotiable as this is a company application and the only available IE is version 8.0. (The reason the above code allows me to write a file to the local PC is because it's an HTML Application (.hta) and thus security restrictions are disabled.)
output.txt from above only ever shows <?xml version="1.0" encoding="utf-8"?>
.
Upvotes: 0
Views: 809
Reputation: 126732
The latest version of MSXML2 is version 2.6, which was last updated in 2004 and is considered obsolete.
I would use a different processing engine if I were you, as this stylesheet works fine for me on all the engines I have access to.
May we know what is in your DTD? I can't think of anything that would prevent the transform from going ahead but it might be nice to see it.
The latest version of MSXML is version 6.0, which is pre-installed on Windows 7. It is available for download from the Microsoft Download Centre for XP.
Update
OK I have had some success. I have found what is probably a bug in MSXML, in that it won't create anything that isn't valid XML as output - even if the output
element in the stylesheet says method="text"
. That's contrary to the XSLT standard, but is typical Microsoft.
See this similar problem on GNT. It looks like the error is because the DOMDocument.transformNodeToObject
is being used to transform to another DOMDocument
object, which can't represent plain text. Apparently it will also accept a simple stream object here, but I didn't look any further as text output isn't a requirement here.
I have got exactly your code working if I remove the DOCTYPE
from the XML and also add a root element around the text your stylesheet outputs, like this
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dxl="http://www.lotus.com/dxl">
<xsl:template match="dxl:document">
<root>
<xsl:text>It worked!</xsl:text>
</root>
</xsl:template>
</xsl:stylesheet>
which produces this output
<?xml version="1.0" encoding="UTF-16"?>
<root xmlns:dxl="http://www.lotus.com/dxl">It worked!</root>
Upvotes: 1