Saxon-JS with sourceNode: issue with object type used?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Saxon-JS with sourceNode: issue with object type used?

France Baril
I can get everything to work with sourceLocation as an input, but not with sourceNode.

Here are the relevant pieces of code. I left my tests in comments. My best guess is that I am not using the right type of js object, but all my trials failed. It might be useful to have an example that uses sourceNode in the documentation.

​JS

$.get(req).done(function(data){
         alert(data);
         //var xmlDoc = $.parseXML(data),
         //xml = $(xmlDoc).get(0);
         //xml = $(xmlDoc).find('title').first();
        
         // Trying as non-jquery object
         var parser = new DOMParser(),
          xmlObject = parser.parseFromString(data , "text/xml");
          var xml = xmlObject.getElementById('template-post-event');
          alert(xml.nodeName + ': ' + xml.nodeType);
         SaxonJS.transform({
           stylesheetLocation: "/static/sef/test-sx.sef",
           sourceNode: xml,
           //initialTemplate: 'main',
           //sourceLocation: '/static/test/test.xml',
           deliverMessage: function(data){console.log('xsl:message: Nav ' + data)}
         });
         //alert(html);
         //$(divId).html(html);
      }, 'string').fail(function (err) {
            alert ('Error. Could not load topic: ' + err.responseText)
      });



XSLT​ start point (Important errors are in yellow):

<xsl:template match="/" name="main">
        
<xsl:message>In main</xsl:message>
        
<!--  This works in my web application with initialTemplate = 'main' -->
        
<!--xsl:result-document href="#get-xml-topic" method="ixsl:replace-content">
            <div>Hello Saxon-JS</div>
         </xsl:result-document-->
     
        
<!-- This works outside the context of the application -->
        
<!--xsl:apply-templates></xsl:apply-templates-->
        
        
<!-- This works with sourceLocation in my web application, but not with sourceNode -->
        
<!-- When initialTemplate is specified, I get an error about a missing context on apply-template -->
        
<!-- When initialTemplate is NOT specified, I am told that no source document, initial template or mode is provided -->

        
<xsl:result-document href="#get-xml-topic" method="ixsl:replace-content">
              
<xsl:apply-templates></xsl:apply-templates>
        
</xsl:result-document>
  
</xsl:template>





--
France Baril
Architecte documentaire / Documentation architect
[hidden email]


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Saxon-JS with sourceNode: issue with object type used?

Martin Honnen-2
On 22.10.2016 01:23, France Baril wrote:
> *var* xml = xmlObject.getElementById('template-post-event');


Does that call find a node? getElementById with XML only works with
attributes defined as ID in the DTD (and most browsers only support
internal DTD subsets), are you doing that in your XML?

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Saxon-JS with sourceNode: issue with object type used?

Martin Honnen-2
On 22.10.2016 10:36, Martin Honnen wrote:
> On 22.10.2016 01:23, France Baril wrote:
>> *var* xml = xmlObject.getElementById('template-post-event');
>
>
> Does that call find a node? getElementById with XML only works with
> attributes defined as ID in the DTD (and most browsers only support
> internal DTD subsets), are you doing that in your XML?

My comment does not seem to appear relevant to the problem, it simply
seems that the Saxon-JS beta does not take into account the sourceNode
or sourceText properties of the options argument to the transform method
when run in the browser, the relevant lines in SaxonJS.js are

         if (inBrowser) {
             if (options.stylesheetLocation === undefined) {
                 throw "No stylesheet supplied";
             }
             platform.asyncGetMultipleXml([options.stylesheetLocation,
options.sourceLocation], function (docs) {
                 stylesheet = docs[options.stylesheetLocation] /*||
options.stylesheetNode*/;
                 sourceDoc = docs[options.sourceLocation] /*||
options.sourceNode*/;
                 applyStylesheet(stylesheet, sourceDoc, options);
                 if (callback) {
                     callback(options.principalResult);
                 }
             })
         }

so the access to options.sourceNode is commented out.



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Saxon-JS with sourceNode: issue with object type used?

debbie
In reply to this post by France Baril

Apologies France, you're right that currently you can only supply a source document using sourceLocation. Martin's assessment is correct: currently the sourceNode transform property is not implemented for use within the browser. It should not be in the documentation yet.

We do intend to get the sourceNode option working in the future, and then the code you tried should work.

Martin has now raised a bug for this, so you can keep track of progress there: https://saxonica.plan.io/issues/3007

Hopefully we can get this fixed for the next beta release.


On 22.10.2016 10:36, Martin Honnen wrote:
On 22.10.2016 01:23, France Baril wrote:
*var* xml = xmlObject.getElementById('template-post-event');
Does that call find a node? getElementById with XML only works with
attributes defined as ID in the DTD (and most browsers only support
internal DTD subsets), are you doing that in your XML?
My comment does not seem to appear relevant to the problem, it simply 
seems that the Saxon-JS beta does not take into account the sourceNode 
or sourceText properties of the options argument to the transform method 
when run in the browser, the relevant lines in SaxonJS.js are

         if (inBrowser) {
             if (options.stylesheetLocation === undefined) {
                 throw "No stylesheet supplied";
             }
             platform.asyncGetMultipleXml([options.stylesheetLocation, 
options.sourceLocation], function (docs) {
                 stylesheet = docs[options.stylesheetLocation] /*|| 
options.stylesheetNode*/;
                 sourceDoc = docs[options.sourceLocation] /*|| 
options.sourceNode*/;
                 applyStylesheet(stylesheet, sourceDoc, options);
                 if (callback) {
                     callback(options.principalResult);
                 }
             })
         }

so the access to options.sourceNode is commented out.



On 22/10/2016 00:23, France Baril wrote:
I can get everything to work with sourceLocation as an input, but not with sourceNode.

Here are the relevant pieces of code. I left my tests in comments. My best guess is that I am not using the right type of js object, but all my trials failed. It might be useful to have an example that uses sourceNode in the documentation.

​JS

$.get(req).done(function(data){
         alert(data);
         //var xmlDoc = $.parseXML(data),
         //xml = $(xmlDoc).get(0);
         //xml = $(xmlDoc).find('title').first();
        
         // Trying as non-jquery object
         var parser = new DOMParser(),
          xmlObject = parser.parseFromString(data , "text/xml");
          var xml = xmlObject.getElementById('template-post-event');
          alert(xml.nodeName + ': ' + xml.nodeType);
         SaxonJS.transform({
           stylesheetLocation: "/static/sef/test-sx.sef",
           sourceNode: xml,
           //initialTemplate: 'main',
           //sourceLocation: '/static/test/test.xml',
           deliverMessage: function(data){console.log('xsl:message: Nav ' + data)}
         });
         //alert(html);
         //$(divId).html(html);
      }, 'string').fail(function (err) {
            alert ('Error. Could not load topic: ' + err.responseText)
      });



XSLT​ start point (Important errors are in yellow):

<xsl:template match="/" name="main">
        
<xsl:message>In main</xsl:message>
        
<!--  This works in my web application with initialTemplate = 'main' -->
        
<!--xsl:result-document href="#get-xml-topic" method="ixsl:replace-content">
            <div>Hello Saxon-JS</div>
         </xsl:result-document-->
     
        
<!-- This works outside the context of the application -->
        
<!--xsl:apply-templates></xsl:apply-templates-->
        
        
<!-- This works with sourceLocation in my web application, but not with sourceNode -->
        
<!-- When initialTemplate is specified, I get an error about a missing context on apply-template -->
        
<!-- When initialTemplate is NOT specified, I am told that no source document, initial template or mode is provided -->

        
<xsl:result-document href="#get-xml-topic" method="ixsl:replace-content">
              
<xsl:apply-templates></xsl:apply-templates>
        
</xsl:result-document>
  
</xsl:template>





--
France Baril
Architecte documentaire / Documentation architect
[hidden email]



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 

-- 
Debbie Lockett
Saxonica

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...