/**
 * xslTransform
 * Tools for XSLT transformations; jQuery wrapper for Sarissa <http://sarissa.sourceforge.net/>.
 * See jQuery.fn.log below for documentation on $.log().
 * See jQuery.fn.getTransform below for documention on the $.getTransform().
 * See var DEBUG below for turning debugging/logging on and off.
 *
 * @version   20071203
 * @since     2006-07-05
 * @copyright Copyright (c) 2006 Glyphix Studio, Inc. http://www.glyphix.com
 * @author    Brad Brizendine <brizbane@gmail.com>, Matt Antone <antone@glyphix.com>
 * @license   MIT http://www.opensource.org/licenses/mit-license.php
 * @requires  >= jQuery 1.0.3			http://jquery.com/
 * @requires  jquery.debug.js			http://jquery.glyphix.com/
 * @requires  >= sarissa.js 0.9.7.6		http://sarissa.sourceforge.net/
 */
var xslTransform={version:20071203,init:function(){try{parseFloat(jQuery.fn.jquery)>=1}catch(e){alert('xslTransform requires jQuery 1.0.4 or greater ... please load it prior to xslTransform')}try{Sarissa}catch(e){alert('Missing Sarissa ... please load it prior to xslTransform')}if(!jQuery.log){jQuery.log=function(){};jQuery.fn.debug=function(){}}jQuery.log('xslTransform:init(): version '+xslTransform.version)},XMLSerializer:new XMLSerializer(),serialize:function(a){jQuery.log('serialize(): received '+typeof(a));if(typeof(a)=='string'){return a}return this.XMLSerializer.serializeToString(a)},load:function(a){jQuery.log('load(): received '+typeof(a));var r;if(typeof(a)=='object'){return a}if(a.substring(0,1)=='<'){r=this.loadString(a)}else{r=this.loadFile(a)}if(r){r.setProperty('SelectionNamespaces','xmlns:xsl="http://www.w3.org/1999/XSL/Transform"');r.setProperty('SelectionLanguage','XPath');return r}else{$.log('Unable to load '+a);return false}},loadString:function(a){jQuery.log('loadString(): '+a+'::'+typeof(a));var p=new DOMParser();var b=p.parseFromString(a,'text/xml');if(!b){jQuery.log('loadString(): parseFromString() failed');return false}return b},loadFile:function(c){jQuery.log('loadFile(): '+c+'::'+typeof(c));if(!c){jQuery.log('ERROR: loadFile() missing url');return false}var d;this.xhrsuccess=function(a,b){jQuery.log('loadFile() completed successfully ('+b+')');d=a;return true};this.xhrerror=function(a,b){window.DEBUG=true;jQuery.log('loadFile() failed to load the requested file: ('+b+') - xml: '+a.responseXML+' - text: '+a.responseText);d=null;return false};$.ajax({type:'GET',url:c,async:false,success:this.xhrsuccess,error:this.xhrerror});if(!d){jQuery.log('ERROR: document '+c+' not found (404), or unable to load');return false}if(d.length==0){jQuery.log('ERROR: document '+c+' loaded in loadFile() has no data');return false}return d},transform:function(a,b,c){var d={'xsl':a,'xml':b,'options':c};jQuery.log('transform(): '+a+'::'+b.xml+'::'+c.toString());c=c||{};var b={'request':b,'doc':this.load(b)};if(c.xpath&&b.doc&&!jQuery.browser.msie){b.doc=b.doc.selectSingleNode(c.xpath.toString());$.log('transform(): xpath has been run...resulting doc: '+(this.serialize(b.doc)))}var e={'xsl':this.load(a)};var f=new XSLTProcessor();f.importStylesheet(e.xsl);if(c.params&&f){jQuery.log('transform(): received xsl params: '+c.params.toString());for(key in c.params){f.setParameter(null,key.toString(),c.params[key].toString())}}e.doc=f.transformToDocument(b.doc);var g=Sarissa.getParseErrorText(e.doc);jQuery.log('transform(): Sarissa parse text: '+g);if(g!=Sarissa.PARSED_OK){e.string=Sarissa.getParseErrorText(e.doc)+' :: using '+a+' => '+b.request;jQuery.log('transform(): error in transformation: '+Sarissa.getParseErrorText(e.doc));return e}e.string=this.serialize(e.doc);e.scripts=jQuery('script',e.doc).text();return e}};xslTransform.init();jQuery.fn.getTransform=function(c,d,f){var g={params:{},xpath:'',eval:true,callback:''};jQuery.extend(g,f);jQuery.log('getTransform: '+c+'::'+d.xml+'::'+g.toString());if(!c||!d){jQuery.log('getTransform: missing xsl or xml');return}return this.each(function(){var a=xslTransform.transform(c,d,g);var b=a.string.match(/<\?xml.*?\?>/);if(b){a.string=a.string.replace(b,'');jQuery.log('getTransform(): found an xml declaration and removed it')}try{$(this).html(a.string)}catch(e){$.log('getTransform: error placing results of transform into element, falling back to innerHTML: '+e.toString());$(this)[0].innerHTML=a.string}if(g.eval&&a.scripts){if(a.scripts.length>0){jQuery.log('Found text/javascript in transformed result');eval.call(window,a.scripts)}}if(g.callback&&jQuery.isFunction(g.callback)){g.callback.apply()}})};
