Can you use jQuery to transform XML into XML through XSLT

I have a website that has links to documents that are dynamically populated based on the type of document, and all the data is in one central XML file. I wanted JQuery to pass the parameter to the stylesheet, the stylesheet selects nodes using xpath based on the passed parameter, and then sorts the notes based on the attribute. From all the documentation I found, jQuery does not support XSLT, and none of the third-party plugins can return a new XML object after converting the original xml. Am I missing something or what am I not trying to do? The xsl file has been tested outside of javascript and works flawlessly

Here is sample code without conversion

$.ajax({ type: "GET", url: "xml/charts.xml", dataType: "xml", success: function(xml) { $(xml).find('chart').each(function(){ // Create link here }); } }); 
+6
source share
3 answers

Another is jquery.xslTransform at http://jquery.glyphix.com/jquery.xslTransform/example/index.html

 // now load both files into variables for the next 2 transformations var xsldoc = $.xsl.load('test.xsl'); var xmldoc = $.xsl.load('test.xml'); // with an xpath $('#with').getTransform( xsldoc, xmldoc, { xpath: '/test/inside' } ); 

Or as indicated in the general documentation:

 $.getTransform( 'path-to-xsl.xsl', // path or xsl document in javascript variable 'path-to-xml.xml', // path or xml document in javascript variable { params: { // object for your own xsl parameters paramName1: 'paramValue1', paramName2: 'paramValue2' }, xpath: '/test/inside', // trims your xml file to that defined by this xpath eval: true, // evaluates any <script> blocks it finds in the transformed result callback: function(){} // getTransform evaluates this function when transformation is complete }); // loads an xml file, parses it and stores it in xmlDoc var xmlDoc = xslTransform.load('path-to-xml.xml'); 

Here is an example of use on a linked page, suggesting that it can satisfy your needs, although it is a javascript-based sarissa shell that attempts to create a browser-independent API for XSL tools in all browsers.

+3
source

You can do XSLT to Javascript conversions, jQuery is not even involved in this process, however, I seriously doubt that you can pass any parameters to the processor.

There is a tutorial on handling XSLT using javascript in w3schools.

+1
source

A more portable implementation is ajaxslt ( http://goog-ajaxslt.sourceforge.net/ ), it is limited, but in many situations it works great. I used it a while ago for proyect, and it even worked in explorer 6.

+1
source

Source: https://habr.com/ru/post/891997/


All Articles