TROIKA.ASP - the MVC framework

XSLEngine.js

Summary

Contains XSLEngine class.

This is part of Troika.ASP Framework - web development MVC framework for ASP 3.0. Please visit www.troika-asp.com for more details.



Version: $Revision: 1.3 $

Author: Pavel Chuchev pav@troika-asp.com


Class Summary
XSLEngine This is XSLEngine class for transforming XSL templates.

/**
* @fileoverview Contains <tt>XSLEngine</tt> class.
*
* <p>
* This is part of Troika.ASP Framework - web development MVC framework for ASP 3.0.
* Please visit {@link http://www.troika-asp.com www.troika-asp.com} for more details.
* </p>
*
* @author Pavel Chuchev pav@troika-asp.com
* @version $Revision: 1.3 $
*/
/**
* Constructs a new instance of XSLEngine class.
*
* @class This is <tt>XSLEngine</tt> class for transforming XSL templates.
*
* @constructor
* @param {String} xslFile The XSL template file to transform.
*/
function XSLEngine(xslFile) {

    if (arguments.length) {

        this.init(xslFile);
    }
}
/**
* Initializes <tt>XSLEngine</tt>.
*
* @param {String} xslFile The XSL template file to transform.
* @return <tt>XSLEngine</tt> object instance itself.
* @type XSLEngine
* @throw Error If xslFile param is not set
*/
XSLEngine.prototype.init = function (xslFile) {

    if (!xslFile) {

        throw new Error("IllegalArgumentException: 'xslFile' not set");
    }

    this.xslfile = xslFile;

    return this;
};
/**
* Transforms XSL template feeding XML data.
*
* @param {String} xml The XML to transform.
* @return The output string as the result of the XML transformation.
* @type String
* @throw Error If there were any errors.
*/
XSLEngine.prototype.transform = function (xml) {

    var xmlDoc =  new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
    var stylesheet =  new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
    var template =  new ActiveXObject("MSXML2.XSLTemplate");

    xmlDoc.async = false;
    stylesheet.async = false;

    xmlDoc.loadXML(xml);

    var err = xmlDoc.parseError;
    if (err.errorCode) {

        var errXMLDoc = {

            doc : "XMLDoc", parseError : err.reason, line : err.line, linepos : err.linepos};
        throw new Error(errXMLDoc.toString());
    }

    stylesheet.load(this.xslfile);
    err = stylesheet.parseError;

    if (err.errorCode) {

        var errTemplDoc = {

            doc : "TemplDoc", parseError : err.reason + ", XSLFile: " + this.xslfile, line : err.line, linepos : err.linepos};

        throw new Error(errTemplDoc.toString());
    }

    template.stylesheet = stylesheet;

    var processor = template.createProcessor();
    processor.input = xmlDoc;

    var result =  new ActiveXObject("ADODB.stream");

    result.Open();
    result.Charset = "iso-8859-1";

    processor.output = result;
    processor.transform();

    result.Position = 0;

    return result.ReadText();
};

TROIKA.ASP - the MVC framework

www.troika-asp.com
Documentation generated on Sun Jun 15 17:59:32 2008