std::string localProfile("'");
localProfile += profileName;
localProfile += "'";
Note that there is an overload of setStylesheetParam() that accepts const
char*, so you do not necessarily need to create XalanDOMString instances to
set the params:
std::string keyActive("active");
xalanTransformer.setStylesheetParam( keyActive.c_str(), localProfile.c_str() );
Dave
Great thanks for your support Dave!
I was re-coding the example to pointing out the problem I had. There was some
unnecessary code involved in the example, when I made the problem request in
harry(I mean hurry ;) for this list. But anyway, here is the original code of
my Transform class. Hopefully this helps someone else.
//Transformer.hpp
#ifndef XCC_TRANSFORMER_H
#define XCC_TRANSFORMER_H
#include <string>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include "WFileHandler.hpp"
#include "CallbackHandler.hpp"
#if defined(XALAN_CLASSIC_IOSTREAMS)
#include <iostream.h>
#else
#include <iostream>
#endif
using namespace std;
class Transformer
{
public:
Transformer(const string& profilename);
~Transformer();
int doTransform();
private:
void initialize();
void finalize();
private:
// Determines some paths
// from the registry in Windows.
WFileHandler* fileHandler;
};
#endif
//Transformer.cpp
extern "C"
{
CallbackSizeType writeCallback( const char* theData,
CallbackSizeType theLength,
void* theHandle)
{
#if defined(XALAN_OLD_STYLE_CASTS)
return ((CallbackHandler*)theHandle)->write(theData, theLength);
#else
return reinterpret_cast<CallbackHandler*>(theHandle)->write(theData,
theLength);
#endif
}
void flushCallback(void* theHandle)
{
#if defined(XALAN_OLD_STYLE_CASTS)
((CallbackHandler*)theHandle)->flush();
#else
reinterpret_cast<CallbackHandler*>(theHandle)->flush();
#endif
}
}
Transformer::Transformer(const string& profilename)
{
fileHandler = new WFileHandler(profilename);
}
Transformer::~Transformer()
{
if(fileHandler)
{
delete fileHandler;
fileHandler = NULL;
}
}
void Transformer::initialize()
{
XALAN_USING_XERCES(XMLPlatformUtils)
XALAN_USING_XALAN(XalanTransformer)
XMLPlatformUtils::Initialize();
XalanTransformer::initialize();
}
void Transformer::finalize()
{
XALAN_USING_XERCES(XMLPlatformUtils)
XALAN_USING_XALAN(XalanTransformer)
XalanTransformer::terminate();
XMLPlatformUtils::Terminate();
}
int Transformer::doTransform()
{
XALAN_USING_STD(cerr)
XALAN_USING_STD(endl)
XALAN_USING_XALAN(XalanTransformer)
int result = -1;
initialize();
FILE* const outputFile = fopen(fileHandler->GetOutputFilePath().c_str(),
"w");
if(outputFile)
{
CallbackHandler cbHandler(outputFile);
XalanTransformer xalanTransformer;
string activeProfile("'");
activeProfile += fileHandler->GetProfileName();
activeProfile += "'";
xalanTransformer.setStylesheetParam("active", activeProfile.c_str());
result = xalanTransformer.transform(
fileHandler->GetInputFilePath().c_str(),
fileHandler->GetTransformationFilePath().c_str(),
&cbHandler,
writeCallback,
flushCallback );
fclose(outputFile);
if(result != 0)
{
cerr << "XalanError: " << xalanTransformer.getLastError() << endl;
}
}
else
{
cerr << "Error: " << "Unable to open output file " <<
fileHandler->GetOutputFilePath().c_str() << endl;
}
finalize();
return result;
}
Harry