xslt
Version:
 [](https://www.npmjs.com/package/xslt) [](https://travis-ci.org/murrayju/x
4 lines (3 loc) • 7.56 kB
JavaScript
/*! xslt v0.9.1+master.0.67dff610fd9b | (c) 2017 Justin Murray | built on 2017-08-09 */
(function(){var e=[].slice,n=[].indexOf||function(e){for(var n=0,r=this.length;n<r;n++)if(n in this&&this[n]===e)return n;return-1};!function(e,n){"function"==typeof define&&null!=define.amd?define([],function(){return n(e)}):"object"==typeof("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=n(e):null!=e&&(e.xslt=n(e))}(this,function(r){var t,l,o,u,i,a,c,s,m,d,f,p,v,x,g,M,D,h,y,N,E,O,X,L,S,T,w,z,b,F,H,P,A;return S={xmlNode:function(){return/<([a-z_][a-z_0-9:\.\-]*\b)\s*(?:\/(?!>)|[^>\/])*(\/?)>/i},xmlLike:function(){return/^\s*</},xmlHeader:function(){return/^\s*<\?xml\b[^<]+/i},namespaces:function(){return/\bxmlns(?::([a-z0-9:\-]+))?\s*=\s*"([^"]*)"/gi}},y=function(e){return S.xmlLike().test(e)},h=function(e){return S.xmlHeader().test(e)},O=function(e){return y(e)&&!h(e)},A=function(e,n){var r;return r='<?xml version="1.0" ',null!=e&&(r+='encoding="'+e+'" '),null!=n&&(r+='standalone="'+n+'" '),r+="?>"},L=function(e,n,r){return A(n,r)+e},b=function(e){return null!=e?e.replace(S.xmlHeader(),""):void 0},g=function(e){var n,r;return(null!=(n=null!=e?e.match(S.xmlHeader()):void 0)?n.length:void 0)&&(null!=(r=n[0])&&"function"==typeof r.trim?r.trim():void 0)||null},v=function(e,n){var r;return(null!=(r=new RegExp("\\b"+n+'\\s*=\\s*"([^"]*)"',"g").exec(e))?r.length:void 0)>1&&r[1]||null},M=function(e){return v(g(e),"encoding")},D=function(e){return v(g(e),"standalone")},l="undefined"!=typeof ActiveXObject&&null!==ActiveXObject||"ActiveXObject"in r,P=function(){var n,r,t,o;if(o=1<=arguments.length?e.call(arguments,0):[],!l)return null;for(n=0,t=o.length;n<t;n++){r=o[n];try{return new ActiveXObject(r)}catch(e){}}return null},c=function(){var e;if(null!=(e=P.apply(null,["Msxml2.FreeThreadedDOMDocument.6.0","Msxml2.FreeThreadedDOMDocument.3.0","Msxml2.FreeThreadedDOMDocument","Microsoft.XMLDOM","Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","Msxml2.DOMDocument.3.0","MSXML2.DOMDocument","MSXML.DOMDocument"])))for(e.async=!1;4!==e.readyState;);return e},s=function(){return P.apply(null,["Msxml2.XSLTemplate.6.0","Msxml2.XSLTemplate"])},E=function(){var e,n;return n=document.createElement("xml"),n.src=A(),document.body.appendChild(n),e=n.XMLDocument,document.body.removeChild(n),e},X=function(){var e,n;return null==(e=null)&&(e=c()),"undefined"!=typeof DOMParser&&null!==DOMParser?e:(null==e&&(e=E()),null==e&&(e=null!=(n=document.implementation)&&"function"==typeof n.createDocument?n.createDocument("","test",null):void 0),e)},T=function(e){var n,r,t,l,o;if("string"!=typeof e||!y(e))return null;if(O(e)&&(e=L(e)),null!=(n=X())&&"loadXML"in n){if(n.loadXML(e),null==n.documentElement||0!==(null!=(r=n.parseError)?r.errorCode:void 0))throw new Error("loadXML error: "+n.parseError)}else if(null!=n&&"load"in n)n.load(e);else if("undefined"!=typeof DOMParser&&null!==DOMParser&&((null!=(n=null!=(t=new DOMParser)&&"function"==typeof t.parseFromString?t.parseFromString(e,"text/xml"):void 0)&&"function"==typeof n.getElementsByTagName&&null!=(l=n.getElementsByTagName("parsererror"))?l.length:void 0)>0||"parsererror"===(null!=n&&null!=(o=n.documentElement)?o.nodeName:void 0)))throw new Error("Failed to load document from string:\r\n"+n.documentElement.textContent);return n},d=function(e){var n,r;return null==e?null:((null!=(r="string"==typeof e?e:null!=(null!=e?e.xml:void 0)?e.xml:"undefined"!=typeof XMLSerializer&&null!==XMLSerializer?null!=(n=new XMLSerializer)&&"function"==typeof n.serializeToString?n.serializeToString(e):void 0:null)&&"function"==typeof r.indexOf?r.indexOf("<transformiix::result"):void 0)>=0&&(r=r.substring(r.indexOf(">")+1,r.lastIndexOf("<"))),r)},x=function(e,n){var r,t,l,o,u,i,a,c;for(r=/\s([a-z0-9:\-]+)\s*=\s*("([^"]*)"|'([^']*)')/gi,t={};a=r.exec(e);)a[0],u=a[1],i=a[2],l=a[3],o=a[4],c={outer:i,inner:l||o},("function"==typeof n?n(u,c):void 0)||(t[u]=c);return t},o=function(e,n,r){var t,l;null==n&&(n={}),null==r&&(r=""),t="<"+e;for(l in n)t+=" "+l+"="+n[l].outer;return t+=r+">"},u=function(e,r,t,l){var u,i,a,c,s,m,d;i=x(e,function(e,r){var t;return/^xmlns/.test(e)&&(t=r.inner,n.call(l.excludedNamespaceUris,t)>=0)}),s=l.includeNamespaces;for(c in s)m=s[c],n.call(function(){var e;e=[];for(a in i)d=i[a],e.push(d.inner);return e}(),m)<0&&(u="xmlns",c.length&&(u+=":"+c),i[u]={outer:'"'+m+'"',inner:m});return o(r,i,t)},z=function(e,r,t,l){var u;return null==l&&(l=[]),u=x(e,function(e,r){var t;return t=r.inner,n.call(l,t)>=0}),o(r,u,t)},H=function(e){return e.replace(/xmlns\s*=\s*""/gi,"")},w=function(e){return e.replace(S.namespaces(),"")},F=function(e){var n,r,t,l;for(l=[],e=e.replace(/xmlns:NS([0-9]+)=""/gi,function(e,n){return l.push(n),""}),n=0,r=l.length;n<r;n++)t=l[n],e=e.replace(new RegExp("NS"+t+":xmlns:","g"),"xmlns:");return e},p=function(e,r){var t;return null==r&&(r=[]),t={},e=null!=e?e.replace(S.namespaces(),function(e,l,o){return null==l&&(l=""),null!=t[l]&&t[l]!==o?e:n.call(r,o)>=0?"":(t[l]=o,"")}):void 0,{xml:e,ns:t}},i=function(e,n){var r,t;return t=[],r=!0,null!=e?e.replace(new RegExp(S.xmlNode().source,"gi"),function(e,l,o){var i,a,c,s,m,d,f;if(n.removeNamespacedNamespace&&(e=F(e)),n.removeNullNamespace&&(e=H(e)),n.removeAllNamespaces&&(e=w(e)),r)for(r=!1,e=u(e,l,o,n),m=x(e,function(e){return!/^xmlns/.test(e)}),t=function(){var e;e=[];for(c in m)f=m[c],e.push(f.inner);return e}(),i=0,a=(s=n.excludedNamespaceUris).length;i<a;i++)d=s[i],t.push(d);else(n.removeDupAttrs||n.removeDupNamespace)&&(e=z(e,l,o,t));return e}):void 0},a=function(e){return null!=e?e.replace(/<(([a-z_][a-z_0-9:\.\-]*\b)\s*(?:\/(?!>)|[^>\/])*)><\/\2>/gi,function(e,n){return"<"+n+"/>"}):void 0},f=function(e){return null!=e?e.replace(/<(([a-z_][a-z_0-9:\.\-]*\b)\s*(?:\/(?!>)|[^>\/])*)\/>/gi,function(e,n,r){return"<"+n+"></"+r+">"}):void 0},m={fullDocument:!1,cleanup:!0,xmlHeaderInOutput:!0,normalizeHeader:!0,encoding:"UTF-8",preserveEncoding:!1,collapseEmptyElements:!0,expandCollapsedElements:!1,removeDupNamespace:!0,removeDupAttrs:!0,removeNullNamespace:!0,removeAllNamespaces:!1,removeNamespacedNamespace:!0,includeNamespaces:{},excludedNamespaceUris:[],moveNamespacesToRoot:!1},N=function(e){var n,r;n={};for(r in m)n[r]=m[r];if(null!=e)for(r in e)n[r]=e[r];return n},t=function(e,n,r){var o,u,i,a,c,m,f,p,v;if(o=N(r),null==(m=T(e)))throw new Error("Failed to load the XML document");if(null==(v=T(n)))throw new Error("Failed to load the XSLT document");return"undefined"!=typeof XSLTProcessor&&null!==XSLTProcessor&&null!=("undefined"!=typeof document&&null!==document&&null!=(a=document.implementation)?a.createDocument:void 0)?((i=new XSLTProcessor).importStylesheet(v),c=o.fullDocument?i.transformToDocument(m):i.transformToFragment(m,document)):"transformNode"in m?c=m.transformNode(v):l&&((p=s()).stylesheet=v,(f=p.createProcessor()).input=m,f.transform(),c=f.output),u=d(c),o.preserveEncoding&&(o.encoding=M(u)||M(e)||o.encoding),o.cleanup&&(u=t.cleanup(u,o)),u},t.cleanup=function(e,n){var r,t,l,o,u,c,s;if((l=N(n)).cleanup){if(l.preserveEncoding&&(l.encoding=M(e)||l.encoding),c=D(e),!l.normalizeHeader&&l.xmlHeaderInOutput||(e=b(e)),l.xmlHeaderInOutput&&O(e)&&(e=L(e,l.encoding,c)),l.moveNamespacesToRoot){t=(o=p(e,l.excludedNamespaceUris)).ns,e=o.xml,u=l.includeNamespaces;for(r in u)s=u[r],t[r]=s;l.includeNamespaces=t}return e=i(e,l),l.collapseEmptyElements&&!l.expandCollapsedElements&&(e=a(e)),l.expandCollapsedElements&&!l.collapseEmptyElements&&(e=f(e)),e}},t})}).call(this);
//# sourceMappingURL=xslt.min.js.map