Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include an xslt stylesheet in a html page

I have some JavaScript that needs to apply an xslt to the result of an ajax request. The xslt is defined in a separate file "transform.xslt" - whats the best way of including the xslt in my page?

Is it possible to use some sort of <link... element, or will I need to make a separate http request myself for the xslt?

like image 621
Justin Avatar asked Nov 06 '22 16:11

Justin


1 Answers

I think you need to use XMLHttpRequest to load the stylesheet from the server, then you have the responseXML and you can use that with the XSLT transformation APIs the browsers expose to Javascript (e.g. importStylesheet with Mozilla and transformNode with IE).

Unless you target IE only where you could use an XML data island with e.g.

<xml id="sheet1" src="sheet.xslt></xml>

in the head section of your HTML document. Then your script could use e.g. someResponseXML.transformNode(sheet1.XMLDocument).

like image 93
Martin Honnen Avatar answered Nov 12 '22 17:11

Martin Honnen