Project

Profile

Help

selecting the xml source programatically

Added by Sam Ryburn over 12 years ago

Would someone kindly point me to an example that demonstrates how to select the source .xml file programatically rather than embedding the file name with the data-source parameter? I will have many source files with the same structure, just different content and would prefer to use a single .html file rather than creating a separate one for every single .xml file. Thanks


Replies (4)

Please register to reply

RE: selecting the xml source programatically - Added by Michael Kay over 12 years ago

This is an important use case that we are still working on; it's probably the main thing that is holding us up from declaring the product fit for general release. We're developing a Javascript API, and also hoping to provide a more declarative way of meeting this requirement without Javascript coding. In the meantime, I don't think there's any obvious way to avoid generating a different .html file for each .xml.

Michael Kay Saxonica

RE: selecting the xml source programatically - Added by Philip Fearon over 12 years ago

I don't know of any examples yet, but you can simply use the standard XPath 2.0 function @fn:doc()@ (or the more complex @fn:document()@ function) to return a document node that you then apply templates to:

...


...

The JavaScript API (as already mentioned by Michael), will provides several alternatives:

  1. From new JavaScript API (showing the procedural version - there's also a JSON-based declarative version):
// load XML files (asynchronous):
var xml1 = Saxon.requestXML('data1.xml');
var xml2 = Saxon.requestXML('data2.xml');
var xml3 = Saxon.requestXML('data3.xml');

// load XSL files
var xsl = Saxon.requestXML('detailer.xsl');
var xsl2 = Saxon.requestXML('detailer2.xsl');

// instantiate processor object with XSL document argument
var proc = new XSLT20Processor(xsl);

// update HTML using xml1 and xml2
proc.updateHTMLDocument(xml1);
proc.updateHTMLDocument(xml2);

// select a new stylesheet
proc.importStylesheet(xsl2);

// upate HTML using xml3 with new stylesheet
proc.updateHTMLDocument(xml3);
  1. From XSLT by referencing XML document nodes passed in as parameters from the JavaScript API, using the XSLT20Processor methods, @setParameter(xml)@ and @setInitialTemplate@:




   
   

  1. In the 1.0 release you can also get references to XML document nodes by calling JavaScript functions from within XSLT using @js:function(arg1, arg2...)@ or @ixsl:call(object, method, arg1, arg2...)@

  2. There are also future plans for an ixsl:transform instruction that would provide much of the flexibility of the JavaScript API but controlled from within the XSLT.

RE: selecting the xml source programatically - Added by Gary Gordon about 12 years ago

I got sidetracked for a while but I'm back into Saxon-CE. I'm not sure exactly what was meant by "programatically" in the original post, but my suggestion of using PHP, just for the purpose of passing data-source filenames to the html framework, was dumb. I don't have any work experience with Javascript, so it didn't occur to me to just use the search property (query string) of the location object, to achieve the same results as my PHP example.

http://www.glasq.com/gary/build/saxon-ce/samples/books2.html?books1.xml http://www.glasq.com/gary/build/saxon-ce/samples/books2.html?books2.xml

However this technique probably still does not address the original question about referencing variable source files programatically.

    (1-4/4)

    Please register to reply