XML/XSL transform using Javascript/JQuery

14,518

Solution 1

I should state from the start that I wrote this script, but if you're looking to just do some transformations and pass some parameters to your XSLT (nothing too fancy) then you can try Magic XML.

You can also have it automatically pull in your data and apply transformations by setting some data- attributes on your DOM elements. For example...

<div data-xml="example.xml" data-xslt="transform.xslt"></div>

...would automatically pull in data from example.xml and apply the transform.xslt to it.

It works in Opera, Chrome, Firefox and IE and is open source.

Solution 2

Have you considered Saxon CE? It used to require a commercial licence for deployment but the latest version has been released as open source.

Solution 3

There's a client side example.

Share:
14,518
cgdeveloper
Author by

cgdeveloper

Updated on June 13, 2022

Comments

  • cgdeveloper
    cgdeveloper almost 2 years

    Can anyone tell me if there is a way to do an XML/XSLT transformation on the client side using Javascript or JQuery, a way that works in all major browsers? (Chrome, Safari, Firefox and IE)? Thanks.

  • pgfearo
    pgfearo about 11 years
    Coincidentally, the open source Saxon-CE 1.1 release was announced on the same day as this answer: Saxon-CE 1.1
  • Ian Roberts
    Ian Roberts about 11 years
    @pgfearo thanks for the heads up, I've edited the answer accordingly.
  • Ishbir
    Ishbir over 10 years
    The MagicXML URL seems to be non-responsive, and I believe it is hosted by you juddging from the domain name. I'm interested in the library.
  • Tom Davies
    Tom Davies over 10 years
    Hey tzot, sorry about that! Updated the URL now, should be good to go.
  • Alexis Wilke
    Alexis Wilke over 9 years
    Which version of XSLT do we end up with? Is it 1.0 or 2.0?
  • yan bellavance
    yan bellavance over 7 years
    does not work when xsl stylesheet contains node-set in edgeHTML 14
  • yan bellavance
    yan bellavance over 7 years
    awesome! the doc is great too!
  • John
    John over 7 years
    @yanbellavance Yes, browsers have moved on a bit since that article was written
  • John
    John over 7 years
    @MarkKCowan Missed your comment when you first posted it, but it only uses MSXML when it detects IE
  • yan bellavance
    yan bellavance over 7 years
    magic xml is just a wrapper around "client side example" found in w3c. It wont fix any upcoming problems. I am wondering if I can reimplement the node-set function using wgx.