Defining a Transformation Object
This example creates a simple transformation object class and then uses the class in the creation of a new transformation object stream.
To insert a transformation into the object stream, use constructors and the corresponding make() functions in the example classes RWXsltObjectInputStreamImp and RWXsltObjectOutputStreamImp.
Each of these classes takes as an additional parameter an ifstream reference to an XSLT stylesheet. But first you need to define a transformation object.
If using Xalan, the transformation object looks like this.
#include <iostream.h>
#include <Include/PlatformDefinitions.hpp> // 1
#include <util/PlatformUtils.hpp>
#include <XalanTransformer/XalanTransformer.hpp>
template <class T>
class RWTXsltTransform
{
public:
RWTXsltTransform(std::basic_istream
<T,std::char_traits<T> >& script) // 2
: script_(script)
{}
void transform(std::basic_istream<T,std::char_traits<T> >& in,
std::basic_ostream<T,std::char_traits<T> >& out)
// 3
{
XalanTransformer transformer; // 4
try {
transformer.transform(&in,&script_,&out); // 5
}
catch(...)
{
throw RWExternalStreamException("RWTXsltTransform::transform():
Transform failed.",RWExternalStreamException::
invalidParameter);
}
private:
std::basic_istream<T,std::char_traits<T> >& script_; // 6
};
This code can be found in buildspace\examples\xmlstreams\xsltTransform\RWTXsltTransform.h and buildspace\examples\xmlstreams\xsltTransform\RWTXsltTransform.ccp.
NOTE: In order to support an XSLT processor other than Xalan, you need to change the lines identified by comments 1, 2, 4 and 5 above. The rest of the code in this example should be the same.