XSLT v0.70

This is a jQuery Plugin for
Google's AJAXSLT. It gives you the ability to transform XML/XSL from JavaScript. AJAXSLT is a parser itself, the library does not depend on your browser being able to do XSL transforms. The plugin also provides functionality to load XML/XSL through $.ajax() calls and transform them.

Table of Contents

XSLT
Table of Contents
License
- Plugin
- AJAXSLT
Download
Demo
Reference
- $.xslt.version
- $.xslt.textToXML(text)
- $.xslt.xmlToText(xml)
- $.xslt(options)
- $(...).xslt(options)
Notes

License

This plugin is divided in two parts for licensing, even though it is a single file. It is clearly marked in the file where my code ends and Google's code begins.

License - Plugin

The part of the code that I made is under MIT or Public Domain license. Whichever suits your needs.

License - AJAXSLT

The code for Google's AJAXSLT is incorporated in the file. This part of the code has the following license:
Copyright (c) 2005,2006 Google Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
        
 * Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the
   distribution.

 * Neither the name of Google Inc. nor the names of its contributors
   may be used to endorse or promote products derived from this
   software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Download

You can download the plugin below. The size of the file is about 115kb, but with JSMin it drops to 68kb, and JSMin+GZ drops it to a mere 15kb.

Download

Demo

This is one of the lamest demo's ever, but you can see it in action in the simplest way
here.

Reference

Reference - $.xslt.version

Object with two members: plugin and ajaxslt.

Reference - $.xslt.textToXML(text)

Converts a text string containing XML to an XML node usable by AJAXSLT. Really just calls the xmlParse function from AJAXSLT. It only exists to provide a jQuery-like function for a common operation.

Reference - $.xslt.xmlToText(xml)

Converts an XML node to a text string. Really just calls the xmlText function from AJAXSLT. It only exists to provide a jQuery-like function for a common operation.

Reference - $.xslt(options)

This is the core of the XSLT plugin and together with the $(...).xslt(options) function probably all you need to use and know about.

This function can take XML and XSL from text strings and XML nodes, if necessary retrieve them from the server through $.ajax() calls both synchronously and asynchronously, use AJAXSLT to do the transformation and provide that back as return value or to a callback or assign it to DOM elements. It also provides caching.

Parameters
All parameters are passed through the options object. Members: Return values
The return value of the function can be either the transformed XML as a text string, true or false. Async vs. Sync
The function running Async or Sync depends on a number of factors.

By default, the function runs sync, and returns the transformation result. However, if any files need to be loaded through $.ajax() calls (which means that they are not in cache or caching is disabled) the function may go async. However, it will only go async if either a callback or target is provided. If no callback or target is provided, the $.ajax() calls will be made sync as well (which can make the browser temporarily unresponsive).

Ofcourse, the callback function is called wether the function goes async or not.

Reference - $(...).xslt(options)

This function is practically the same as the $.xslt(options) function. The differences are that the target option is automatically set to the jQuery object and the function returns this to maintain chainability instead of true, false, or html.

Notes

AJAXSLT is a very nice library, but it does not implement XSLT in full. Most common things are supported though. It also breaks fairly easily and it can be hard to find where the problem is at.

Ofcourse, the plugin has not changed the AJAXSLT code, so it's function names run the risk of conflicting with your own.

Laters

Laters and have fun,
- Chainfire