SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript error with Thomas Myer's XML Web Development book script help needed

    Hello,

    I'm working my way through Thomas Myer's sitepoint book "XML Web Development with PHP". On page 149 a script is presented using javascript and DOM to provide cross-browser support - except that it doesn't.

    I get a Javascript error saying "object required" when using IE, though the script is fine in Firefox.

    Anyone else hit this problem, and better still know how to fix it?

    Thanks

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,458
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    javascript error

    I don't have that book, but if you post the problem code I, or someone else, may be able to help you solve it.

  3. #3
    SitePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The most common source of a missing object is running a script before a page has fully loaded. That's why many scripts are fired by the window.onload event.

  4. #4
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the code concerned, jstest.html followed by the xml and xsl data:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Processing XML/XSLT with JavaScript</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" src="sarissa/sarissa.js"></script>
    <script type="text/javascript">
    var xml = Sarissa.getDomDocument();
    xml.async = false;
    xml.load("test.xml");

    var xsl = Sarissa.getDomDocument();
    xsl.async = false;
    xsl.load("test.xsl");

    window.onload = function() {
    var xslt = new XSLTProcessor();
    xslt.importStylesheet(xsl);
    var out = xslt.transformToDocument(xml);
    var docBody = document.getElementsByTagName('body').item(0);
    var outBody = out.documentElement.childNodes.item(1);
    // Clear the current document body
    while (docBody.hasChildNodes()) {
    docBody.removeChild(docBody.firstChild);
    }
    // Refill it with the 'out' document body's children
    for (var i = 0; i < outBody.childNodes.length; i++) {
    var node = outBody.childNodes.item(i);
    node = document.importNode(node, true);
    docBody.appendChild(node);
    }
    };
    </script>
    </head>

    <body>
    </body>
    </html>

    test.xml
    <?xml version="1.0" encoding="iso-8859-1"?>
    <body>
    <header>This is a simple headline</header>
    <para>Some random text. Notice that in our XML source, we aren't pointing to a specific XSLT file.</para>
    </body>

    test.xsl
    <xsl:stylesheet version="1.0"
    xmlnssl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/1999/xhtml">

    <xslutput method="xml" indent="yes" omit-xml-declaration="yes"
    media-type="application/xhtml+xml" encoding="iso-8859-1"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

    <xsl:template match="body">
    <html>
    <head>
    <title>Processing XML/XSLT with JavaScript</title>
    <meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1"/>
    </head>
    <body>
    <xsl:apply-templates/>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="header">
    <h1><xsl:apply-templates/></h1>
    </xsl:template>

    <xsl:template match="para">
    <p><xsl:apply-templates/></p>
    </xsl:template>

    </xsl:stylesheet>

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,458
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    paths

    In the folder that has the "Processing XML/XSLT with JavaScript" file there needs to be the test.xml and test.xsl files and a folder named sarissa containing the sarissa.js file. Also, if sarissa.js uses other files they need to be in the right place with the right names too. Is this so?
    Seeing as it works in Firefox but not IE, I imagine this is not the problem. I'll check out the sarissa source and post back.

    EDIT*
    From sarissa.js http://sarissa.sourceforge.net/doc/o...arissa.js.html
    * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs.
    * The library supports Gecko based browsers like Mozilla and Firefox,
    * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and a little of Opera
    Are you using IE 5.5+ with MSXML3.0+ ??

  6. #6
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe all the files are in the right places. I using IE 6.0.2900.2180.

    The line it fails on is:
    var xslt = new XSLTProcessor();

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,458
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    XSLTProcessor

    Maybe if you tried
    Code:
    var xslt = Sarissa.XSLTProcessor();
    ??

  8. #8
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems to work fine when the internet connection is available, I was previously using it on a virtual machine which didn't have an internet connection from that domain.

    Thanks for looking at it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •