post a parameter dom to xsl for Safari

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason

    post a parameter dom to xsl for Safari

    Hi all,
    Are you familiar with Safari? I have a site that works perfectly in
    IE6 IE7 FF2 FF3 but not in the
    latest Safari. When I test xsltProcessor, there is a error as
    following, I have dealt with this issue for several days, but there is
    no result. Could someone help me?

    [Code]
    <html>
    <head>
    <title>Enter the title of your HTML document here</title>
    <script type="text/javascript">
    var xmlDoc;
    var xsltDoc;
    var xmlFile="Test_x sltProcessor.xm l";
    var xsltFile="Test_ xsltProcessor.x sl";

    function show_xml()
    {
    // Firefox, Opera 8.0+, Safari
    if(document.imp lementation &&
    document.implem entation.create Document)
    {
    //load xml file
    XMLDocument.pro totype.load = function(filePa th)
    {
    var xmlhttp = new XMLHttpRequest( );
    xmlhttp.open("G ET", filePath, false);
    xmlhttp.setRequ estHeader("Cont ent-Type","text/xml");
    xmlhttp.send(nu ll);
    var newDOM = xmlhttp.respons eXML;
    if( newDOM )
    {
    var newElt = this.importNode (newDOM.documen tElement, true);
    this.appendChil d(newElt);
    return true;
    }
    }
    xmlDoc = document.implem entation.create Document("", "",
    null);
    xmlDoc.async = false;
    xmlDoc.load(xml File);

    //load xsl file
    var xsltDoc = document.implem entation.create Document("",
    "", null);
    xsltDoc.async = false;
    xsltDoc.load(xs ltFile);

    //build the relationship between xml file and xsl file
    var xslt = new XSLTProcessor() ;
    xslt.importStyl esheet(xsltDoc) ;

    //set parameters
    xslt.setParamet er( null, 'testDom', xmlDoc);

    //transform
    var doc = xslt.transformT oFragment(xmlDo c, document);
    //append the xml result to the main html file
    var target=document .getElementById ("divContent ");
    while (target.hasChil dNodes())
    {
    target.removeCh ild(target.last Child);
    }
    target.appendCh ild(doc);
    }
    else if(typeof window.ActiveXO bject != 'undefined')
    {
    //load xml file
    xmlDoc = new ActiveXObject(' Microsoft.XMLDO M');
    xmlDoc.async = false;
    xmlDoc.load(xml File);

    //load xsl file
    xsltDoc = new ActiveXObject(' Microsoft.XMLDO M');
    xsltDoc.async = false;
    xsltDoc.load(xs ltFile);

    //append the xml result to the main html file
    var target=document .getElementById ("divContent ");
    target.innerHTM L = xmlDoc.document Element.transfo rmNode(xsltDoc) ;
    }
    }
    </script>
    </head>
    <body onload="show_xm l();">
    <p>Enter the body text of your HTML document here</p>
    <div id="divContent" ></div>
    </body>
    </html>

    The xsl file is as following:
    <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/
    Transform">
    <xsl:param name="testDom"/>
    <xsl:template match="/">
    <div>
    <xsl:value-of select="$testDo m"/>
    </div>
    </xsl:template>
    </xsl:stylesheet>

    The xml file is as following:
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <test>ccc</test>
    </root>

    In Safari, the output is [object Document] --It changes to
    string$B!$(Bb ut in IE and
    Firefox, the output is aaa.

    Could someone help me? Thanks!
  • Martin Honnen

    #2
    Re: post a parameter dom to xsl for Safari

    Jason wrote:
    The xsl file is as following:
    <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/
    Transform">
    <xsl:param name="testDom"/>
    <xsl:template match="/">
    <div>
    <xsl:value-of select="$testDo m"/>
    </div>
    </xsl:template>
    </xsl:stylesheet>
    >
    The xml file is as following:
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <test>ccc</test>
    </root>
    >
    In Safari, the output is [object Document] --It changes to
    string$B!$(Bb ut in IE and
    Firefox, the output is aaa.
    For you IE you do not even set the parameter testDom before the
    transformation so why should IE output something for <xsl:value-of
    select="$testDo m"/>? That does not make sense.
    And why should Firefox output 'aaa' if the 'test' element in the
    document contains 'ccc'? That does not make sense either.

    What exactly is it that you want to achieve? If you have a primary input
    document for your XSLT transformation then why do you want to pass the
    same document as a parameter? That does not make much sense either,
    unless you want to test whether the XSLT implementation supports passing
    in a DOM document as the parameter.



    --

    Martin Honnen

    Comment

    • Jason

      #3
      Re: post a parameter dom to xsl for Safari

      On 8ÔÂ15ÈÕ, ÏÂÎç7ʱ00·Ö, Martin Honnen <mahotr...@yaho o.dewrote:
      Jason wrote:
      The xsl file is as following:
      <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/
      Transform">
      <xsl:param name="testDom"/>
      <xsl:template match="/">
      <div>
      <xsl:value-of select="$testDo m"/>
      </div>
      </xsl:template>
      </xsl:stylesheet>
      >
      The xml file is as following:
      <?xml version="1.0" encoding="UTF-8"?>
      <root>
      <test>ccc</test>
      </root>
      >
      In Safari, the output is [object Document] --It changes to
      string£¬but in IE and
      Firefox, the output is aaa.
      >
      For you IE you do not even set the parameter testDom before the
      transformation so why should IE output something for <xsl:value-of
      select="$testDo m"/>? That does not make sense.
      And why should Firefox output 'aaa' if the 'test' element in the
      document contains 'ccc'? That does not make sense either.
      >
      What exactly is it that you want to achieve? If you have a primary input
      document for your XSLT transformation then why do you want to pass the
      same document as a parameter? That does not make much sense either,
      unless you want to test whether the XSLT implementation supports passing
      in a DOM document as the parameter.
      >
      --
      >
      Martin Honnen
      http://JavaScript.FAQTs.com/- Òþ²Ø±»ÒýÓÃÎÄ×Ö -
      >
      - ÏÔʾÒýÓõÄÎÄ×Ö -
      Hi,
      I'm sorry,the xml file should be as following:
      <?xml version="1.0" encoding="UTF-8"?>
      <root>
      <test>aaa</test>
      </root>

      You are right. I want to test whether the XSLT implementation supports
      passing
      in a DOM document as the parameter.
      Could you help me have a look at the issue? Any help will be much
      appreciated.

      Comment

      • Jason

        #4
        Re: post a parameter dom to xsl for Safari

        On 8ÔÂ17ÈÕ, ÏÂÎç5ʱ58·Ö, Jason <ydsh...@gmail. comwrote:
        On 8ÔÂ15ÈÕ, ÏÂÎç7ʱ00·Ö, Martin Honnen <mahotr...@yaho o.dewrote:
        >
        >
        >
        >
        >
        Jason wrote:
        The xsl file is as following:
        <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/
        Transform">
        <xsl:param name="testDom"/>
        <xsl:template match="/">
        <div>
        <xsl:value-of select="$testDo m"/>
        </div>
        </xsl:template>
        </xsl:stylesheet>
        >
        The xml file is as following:
        <?xml version="1.0" encoding="UTF-8"?>
        <root>
        <test>ccc</test>
        </root>
        >
        In Safari, the output is [object Document] --It changes to
        string£¬but in IE and
        Firefox, the output is aaa.
        >
        For you IE you do not even set the parameter testDom before the
        transformation so why should IE output something for <xsl:value-of
        select="$testDo m"/>? That does not make sense.
        And why should Firefox output 'aaa' if the 'test' element in the
        document contains 'ccc'? That does not make sense either.
        >
        What exactly is it that you want to achieve? If you have a primary input
        document for your XSLT transformation then why do you want to pass the
        same document as a parameter? That does not make much sense either,
        unless you want to test whether the XSLT implementation supports passing
        in a DOM document as the parameter.
        >
        --
        >>
        - ÏÔʾÒýÓõÄÎÄ×Ö -
        >
        Hi,
        I'm sorry,the xml file should be as following:
        <?xml version="1.0" encoding="UTF-8"?>
        <root>
        <test>aaa</test>
        </root>
        >
        You are right. I want to test whether the XSLT implementation supports
        passing
        in a DOM document as the parameter.
        Could you help me have a look at the issue? Any help will be much
        appreciated.- Òþ²Ø±»ÒýÓÃÎÄ×Ö -
        >
        - ÏÔʾÒýÓõÄÎÄ×Ö -
        And the html should be like as following:
        [Code]
        <html>
        <head>
        <title>Enter the title of your HTML document here</title>
        <script type="text/javascript">
        var xmlDoc;
        var xsltDoc;
        var xmlFile="Test_x sltProcessor.xm l";
        var xsltFile="Test_ xsltProcessor.x sl";


        function show_xml()
        {
        // Firefox, Opera 8.0+, Safari
        if(document.imp lementation &&
        document.implem entation.create Document)
        {
        //load xml file
        XMLDocument.pro totype.load = function(filePa th)
        {
        var xmlhttp = new XMLHttpRequest( );
        xmlhttp.open("G ET", filePath, false);
        xmlhttp.setRequ estHeader("Cont ent-Type","text/xml");
        xmlhttp.send(nu ll);
        var newDOM = xmlhttp.respons eXML;
        if( newDOM )
        {
        var newElt = this.importNode (newDOM.documen tElement,
        true);
        this.appendChil d(newElt);
        return true;
        }
        }
        xmlDoc = document.implem entation.create Document("", "",
        null);
        xmlDoc.async = false;
        xmlDoc.load(xml File);


        //load xsl file
        var xsltDoc = document.implem entation.create Document("",
        "", null);
        xsltDoc.async = false;
        xsltDoc.load(xs ltFile);


        //build the relationship between xml file and xsl file
        var xslt = new XSLTProcessor() ;
        xslt.importStyl esheet(xsltDoc) ;


        //set parameters
        xslt.setParamet er( null, 'testDom', xmlDoc);


        //transform
        var doc = xslt.transformT oFragment(xmlDo c, document);
        //append the xml result to the main html file
        var target=document .getElementById ("divContent ");
        while (target.hasChil dNodes())
        {
        target.removeCh ild(target.last Child);
        }
        target.appendCh ild(doc);
        }
        else if(typeof window.ActiveXO bject != 'undefined')
        {
        //load xml file
        xmlDoc = new ActiveXObject( "MSXML2.FreeThr eadedDomDocumen t.
        3.0" );
        xmlDoc.async = false;
        xmlDoc.load(xml File);


        //load xsl file
        xsltDoc = new ActiveXObject( "MSXML2.FreeThr eadedDomDocumen t.
        3.0" );
        xsltDoc.async = false;
        xsltDoc.load(xs ltFile);

        var template = new ActiveXObject( "MSXML2.XSLTemp late.
        3.0" );
        template.styles heet = xsltDoc;
        var processor = template.create Processor();
        processor.input = xmlDoc;
        processor.addPa rameter("testDo m",xmlDoc);
        processor.trans form();

        //append the xml result to the main html file
        var target=document .getElementById ("divContent ");
        target.innerHTM L = processor.outpu t;;
        }
        }
        </script>
        </head>
        <body onload="show_xm l();">
        <p>Enter the body text of your HTML document here</p>
        <div id="divContent" ></div>
        </body>
        </html>

        Comment

        • Martin Honnen

          #5
          Re: post a parameter dom to xsl for Safari

          Jason wrote:
          You are right. I want to test whether the XSLT implementation supports
          passing
          in a DOM document as the parameter.
          Could you help me have a look at the issue? Any help will be much
          appreciated.
          Based on your test result it sounds as if Safari converts the DOM
          document node to a string and passes that string in.


          --

          Martin Honnen

          Comment

          • Jason

            #6
            Re: post a parameter dom to xsl for Safari

            On 8ÔÂ17ÈÕ, ÏÂÎç6ʱ50·Ö, Martin Honnen <mahotr...@yaho o.dewrote:
            Jason wrote:
            You are right. I want to test whether the XSLT implementation supports
            passing
            in a DOM document as the parameter.
            Could you help me have a look at the issue? Any help will be much
            appreciated.
            >
            Based on your test result it sounds as if Safari converts the DOM
            document node to a string and passes that string in.
            >
            --
            >
            Martin Honnen
            http://JavaScript.FAQTs.com/
            Hi Martin,
            Yes, Safari converts the DOM document node to a string and passes the
            string in. I can use the following code to test it.
            [code]
            var testDom = xslt.getParamet er(null,'testDo m')
            alert(typeof(te stDom))

            It ouputs string.

            Comment

            Working...