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
};
//1 Include the Xalan header files. If you are using another XSLT processor, your includes will be different.
//2 The constructor for the Xalan transformation object takes a stream reference from which the XSLT script can be read. This reference is stored in a member variable (To use a different XSLT processor you'll need to change this line).
//3 The transform() method of the transformation object takes an input stream and an output stream. The source document will be read from the input and the transformed document written to the output.
//4 Within the transform() method, you first create a Xalan transformation object, then
//5 Call the Xalan transformation object using the source document stream, the output document stream and the saved XSLT script stream. (To use an XSLT processor other than Xalan you'll also need to change these lines.)
//6 The member variable for holding the reference to the XSLT script.
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.