/**
 * Transform a XML document.
 * The stylesheet is retrieved by a processing instruction,
 * or an error is returned.
 */
nsresult
txStandaloneXSLTProcessor::transform(txXPathNode& aXMLDoc, ostream& aOut,
                                     ErrorObserver& aErr)
{
    Document* xmlDoc;
    nsresult rv = txXPathNativeNode::getDocument(aXMLDoc, &xmlDoc);
    NS_ENSURE_SUCCESS(rv, rv);

    // get stylesheet path
    nsAutoString stylePath, basePath;
    xmlDoc->getBaseURI(basePath);
    getHrefFromStylesheetPI(*xmlDoc, stylePath);
    txParsedURL base, ref, resolved;
    base.init(basePath);
    ref.init(stylePath);
    base.resolve(ref, resolved);

    nsRefPtr<txStylesheet> style;
    rv = TX_CompileStylesheetPath(resolved, getter_AddRefs(style));
    NS_ENSURE_SUCCESS(rv, rv);

    // transform
    rv = transform(aXMLDoc, style, aOut, aErr);

    return rv;
}
 int loadStylesheet (char * filename)
 {
     txParsedURL url;
     url.init(NS_ConvertASCIItoUTF16(filename));
     nsresult rv =
         TX_CompileStylesheetPath(url, getter_AddRefs(mStylesheet));
     return NS_SUCCEEDED(rv) ? 0 : 1;
 }
/**
 * Transform a XML document given by path with the given
 * stylesheet.
 */
nsresult
txStandaloneXSLTProcessor::transform(nsACString& aXMLPath,
                                     nsACString& aXSLPath, ostream& aOut,
                                     ErrorObserver& aErr)
{
    txXPathNode* xmlDoc = parsePath(aXMLPath, aErr);
    if (!xmlDoc) {
        return NS_ERROR_FAILURE;
    }
    txParsedURL path;
    path.init(NS_ConvertASCIItoUCS2(aXSLPath));
    nsRefPtr<txStylesheet> style;
    nsresult rv = TX_CompileStylesheetPath(path, getter_AddRefs(style));
    if (NS_FAILED(rv)) {
        delete xmlDoc;
        return rv;
    }
    // transform
    rv = transform(*xmlDoc, style, aOut, aErr);

    delete xmlDoc;

    return rv;
}