开发者

xsltProcessor.importStylesheet error

Im trying to work with following code i getting this error at xsltProcessor.importStylesheet

Error when i removed: xhttp.send(null);

uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIXSLTProcessor.importStylesheet]"  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"  location: "JS frame :: file:///C:/Users/bobby/Desktop/geocoding.html :: displayResult :: line 35"  data: no]

Line 0

Error when i have: xhttp.send(null);

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: file:///C:/Users/bobby/Desktop/geocoding.html :: loadXMLDoc :: line 16"  data: no]

Line 0

My html file:

<html>
<head>
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",dname,false);

return xhttp.responseXML;
}

function displayResult()
{ 
xml=loadXMLDoc("http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false");
alert("successful call to xml");
xsl=loadXMLDoc("latitude.xsl");
alert("successful applying style sheet");
// code for IE
if (window.ActiveXObject)
  {
  ex=xml.transformNode(xsl);
  document.getElementById("example").innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  document.getElementById("example").appendChild(resultDocument);
  }
}
</script>
</开发者_如何学Chead>
<body onload="displayResult()">
<div id="example" />
</body>
</html>

My Xslt style sheet as requested:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/"> 
  <html>
  <body>
  <h2>Latitude Longitute finder</h2>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Latitude</th>
      <th>Longitude</th>
    </tr>
    <tr>
      <td><xsl:value-of select="GeocodeResponse/result/geometry/location/lat"/></td>
      <td><xsl:value-of select="GeocodeResponse/result/geometry/location/lng"/></td>
<td><xsl:value-of select="GeocodeResponse/result/type"/></td>
<td><xsl:value-of select="GeocodeResponse/result/formatted_address"/></td>
<td><xsl:value-of select="GeocodeResponse/result/address_component/long_name"/></td>
<td><xsl:value-of select="GeocodeResponse/result/address_component/short_name"/></td>
    </tr>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>


Well unless your HTML document with the script is hosted on http://maps.googleapis.com/ your script is not allowed to load documents with XMLHttpRequest from that origin, due to the same origin policy in place for client-side code in browsers. So I would expect a browser like Mozilla to throw an exception on the send call if you are trying to load data from http://maps.googleapis.com/. As for the error on the importStylesheet, consider to show a minimal but complete stylesheet allowing us to reproduce the error. Or better yet, first run the stylesheet outside of the browser through an XSLT 1.0 processor which gives you better error messages, I suspect there is simply a problem in the stylesheet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜