{ Frameless }

XSLT2Processor.transformToFragment()

The transformToFragment($source, $ownerDocument) function specifies that the transformation should result in a DocumentFragment.

When the templates are meant to create new elements for the current HTML page, this method is for you:


frag = xslt.transformToFragment(window.document)
document.body.appendChild(frag)

window.document says the template output is meant to be used in the current document.

Element must be created specifically for one document, that's why it's necessary to specify the document up front. Using this methods cousin transformToDocument() generates the output in it's very own document, which also means they're not usable in your HTML page.

var xslt = new XSLT2Processor;
xslt.importStylesheetURI("test.xsl");
var doc = sync_GET("test.xml");
var output = xslt.transform(doc);
document.body.appendChild(output);

Or using the jQuery plugin:

$
    .doc('test.xml')
    .xslt('test.xsl')
    .appendTo('body')