Jump to content

Call to document() in IE8


acangi

Recommended Posts

Hello,I'm trying to do an XSLT transform in the browser, based on the w3schools example. This works fine in firefox, but not yet in IE8, which seems to block on the document() function in the XSL.Javascript code :

			function loadXMLDoc(dname) 			{ 				if (window.XMLHttpRequest){ 					xhttp=new XMLHttpRequest(); 				} 				else { 					xhttp=new ActiveXObject("Microsoft.XMLHTTP"); 				} 				xhttp.open("GET",dname,false); 				xhttp.send(""); 				return xhttp.responseXML; 			} 			 			function transform() { 				xml=loadXMLDoc("srv/en/xml.metadata.get?uuid=%7B0644DAD6-6333-43B6-A5F5-83B542650DE7%7D"); 				xsl=loadXMLDoc("test.xsl"); 				 				// code for IE 				if (window.ActiveXObject) { 					xsl=loadXMLDoc("test.xsl"); 					xsl.setProperty("AllowDocumentFunction", true); 					ex=xml.transformNode(xsl); 					document.getElementById("result_list").innerHTML=ex; 				} 				// code for Mozilla, Firefox, Opera, etc. 				else if (document.implementation && document.implementation.createDocument) { 					//xsl=loadXMLDoc("metadata_ngi.xsl"); 					xsltProcessor=new XSLTProcessor(); 					xsltProcessor.importStylesheet(xsl); 					resultDocument = xsltProcessor.transformToFragment(xml,document); 					document.getElementById("result_list").appendChild(resultDocument); 				} 			}

XSL code :

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"  		xmlns:gmd="http://www.isotc211.org/2005/gmd" >  	<xsl:variable name="label" select="document('./xml/schemas/iso19139/loc/nl/labels.xml')"/> 	 	<xsl:template match="/"> 		<div> 			<xsl:call-template name="getTitle"> 				<xsl:with-param name="name" select="name(gmd:MD_Metadata)"/> 			</xsl:call-template> 		</div> 	</xsl:template>  	<xsl:template name="getTitle"> 		<xsl:param name="name"/> 		<xsl:value-of select="name(.)"/> 		<xsl:value-of select="string($label/labels/element[@name=$name]/label)"/> 	</xsl:template> 	  </xsl:stylesheet>

Do you have an idea how to get this working in IE ?Alain

Link to comment
Share on other sites

Paths in XSLT are evaluated relative to the XSLT file's location I belive... assuming test.xsl is actually located at

http://example.com/test.xsl

is the extra XML located at

http://example.com/xml/schemas/iso19139/loc/nl/labels.xml

?Is the file actually accessed on an HTTP page, or is it on a local file system? That would probably create problems too.

Link to comment
Share on other sites

Thanks for your replies,

Can you describe in detail what happens? Do you get an error with IE, if so which one exactly? The documentation http://msdn.microsoft.com/en-us/library/ms...v=VS.85%29.aspx suggests if the "document" function is disabled that you get an "access denied".
Sorry, I forgot to mention the error code. It is indeed an "Access is denied" error. This code works fine in firefox. It also works in IE8 if I remove the call to the getTitle template, making me assume that the problem is the document() function. I added a line
xsl.setProperty("AllowDocumentFunction", true);

in the javascript code (it's already present in the first post) but the error remains the same.

Paths in XSLT are evaluated relative to the XSLT file's location I belive... assuming test.xsl is actually located at
http://example.com/test.xsl

is the extra XML located at

http://example.com/xml/schemas/iso19139/loc/nl/labels.xml

?Is the file actually accessed on an HTTP page, or is it on a local file system? That would probably create problems too.

As it works in firefox and not in IE, I assume the path is correct. Indeed the files are accessible viahttp://10.1.110.112:8080/geonetwork/test.xsl and http://10.1.110.112:8080/geonetwork/xml/sc...c/nl/labels.xmlI think I don't get the question about HTTP page or local filesystem. Both files (test.xml and labels.xml) are on the same server. The client (here IE8) is on my desktop, which is not the same machine. First the html page is gotten from the server. The html page downloads the xml and test.xsl files and transforms them to html (see html code in my first post). test.xsl should get the labels.xml via the document() function. I guess this happens when IE8's XSLT processor reads test.xsl, so it should make a new HTTP request to get labels.xml.
Link to comment
Share on other sites

If placing the full URL worked, then this is a relative URL issue... perhaps the base is the XML document, not the XSLT... or for some reason MSXML has problems with URLs starting with "."...Well, try to use

document('/geonetwork/xml/schemas/iso19139/loc/nl/labels.xml')

And if that too works, try

document('../../xml/schemas/iso19139/loc/nl/labels.xml')

and

document('xml/schemas/iso19139/loc/nl/labels.xml')

Whichever is shortest and works, it's probably the one you should keep.

Link to comment
Share on other sites

Whichever is shortest and works, it's probably the one you should keep.
As it works now, I consider my problem solved, but for information for the next one who'll have this problem : the only string that works in IE is the complete URL, starting with 'http'. in FF it works when starting with 'http' or './xml'.It wouldn't surprise me if IE was looking for the file on the client... :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...