Koozali.org: home of the SME Server

Obsolete Releases => SME Server 7.x => Topic started by: egas on May 22, 2007, 11:41:29 PM

Title: xml parsing troubles
Post by: egas on May 22, 2007, 11:41:29 PM
I have a webpage that I am trying to display records from an xml file. I am using a xsl file for formatting. The XSL file also has a parameter to limit the records returned.  

For some reason, I am unable to get the script to work in Firefox (IE works fine) when the webpage is hosted on a SME Server v7 (tried on 2 different SME installations).  

I get this in the Error Console of Firefox:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXSLTProcessor.transformToFragment]"  nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  location: "JS frame :: http://linuxtest/test.htm :: <TOP_LEVEL> :: line 61"  data: no]

I also tested this webpage locally and it works for both browsers.  I even tested the webpage running on an IIS 5 web server and it worked for both browsers.  So this points me to something with the SME server as being the trouble point.  What that is I cannot figure out and was hoping someone has a suggestion.  I can post the xml, xsl, and html code if needed.
Title: xml parsing troubles
Post by: egas on May 24, 2007, 08:00:35 PM
Maybe it would help if I posted the code.  If someone could try this sample code (I only left what I was trying to get to work) on one of their test SME servers and let me know if it works or not using Firefox I would appreciate it.

Again, I know the webpage works in Firefox when I run the code via a mapped drive to the ibay folder but not when viewing via http.  IE works fine via http.  It also works fine for both browsers when the webpage is running on IIS 5 web server.

HTML document called "test.htm"
Code: [Select]
<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY class="bodydefault">
<!-- Begin Table -->

<div id="custlist">LOCATIONS</div>
<script type="text/javascript">
// code for IE
if (window.ActiveXObject)
{
var xslDoc;
var xslt;
var xmlDoc;
var xslProc;

xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("test.xsl");
xslt = new ActiveXObject("Msxml2.XSLTemplate");
xslt.stylesheet = xslDoc;

xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("test.xml");

xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.addParameter("param1", 1);
xslProc.transform();

document.getElementById("custlist").innerHTML = xslProc.output;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
var xslStylesheet;
var xsltProcessor = new XSLTProcessor();
var xmlDoc;

// load the xslt file
var myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "test.xsl", false);
myXMLHTTPRequest.send(null);

xslStylesheet = myXMLHTTPRequest.responseXML;
xsltProcessor.importStylesheet(xslStylesheet);

// load the xml file
myXMLHTTPRequest = new XMLHttpRequest();
myXMLHTTPRequest.open("GET", "test.xml", false);
myXMLHTTPRequest.send(null);

xmlDoc = myXMLHTTPRequest.responseXML;

xsltProcessor.setParameter(null, "param1", 1);

var fragment = xsltProcessor.transformToFragment(xmlDoc, document);

document.getElementById("custlist").innerHTML = "";

document.getElementById("custlist").appendChild(fragment);
}
else
{
document.getElementById("custlist").innerHTML = "Your browser cannot handle this script.";
}
</script>
</BODY>
</HTML>


XML document called "test.xml"
Code: [Select]
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
  <custlistweb>
    <CustomerName>C1Name</CustomerName>
    <RegionCode>1</RegionCode>
  </custlistweb>
  <custlistweb>
    <CustomerName>C2Name</CustomerName>
    <RegionCode>2</RegionCode>
  </custlistweb>
  <custlistweb>
    <CustomerName>C3Name</CustomerName>
    <RegionCode>1</RegionCode>
  </custlistweb>
</DocumentElement>


XSL document called "test.xsl"
Code: [Select]
<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">
<xsl:output method="html"/>
<xsl:param name="param1"/>

<!-- Template for our root rule -->
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<!-- Template for our "DocumentElement" rule -->
<xsl:template match="DocumentElement">

<xsl:for-each select="custlistweb">

<xsl:if test="RegionCode=$param1">
   
<!--Display node detail-->
<span class="custname"> <xsl:value-of select="CustomerName" /></span><br />
       <br />
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Title: xml parsing troubles
Post by: judgej on May 27, 2007, 01:37:08 AM
Quote from: "egas"
Maybe it would help if I posted the code...


It would help if you posted to a more appropriate forum. This has nothing to do with SME Server, has it?

JavaScript, AJAX, DOM manipulation, browser-based XSLT transformation and browser compatibility is a whole different world to what this forum is about.

-- JJ