Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
XML Streams Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

6.2 Creating the Objects and Streams

This section describes how to create objects and streams.

6.2.1 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.

//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.


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.

6.2.2 Defining a Character Transformation Stream

Next, define character transformation streams to go with this transform object.

These input and an output streams will be used to create your XSLT transformation stream.

6.2.3 Defining an XSLT Transformation Stream

Finally define the XSLT transformation stream using the transform object and the character transformation stream. You'll define an input XSLT transformation stream and an output XSLT transformation stream.

6.2.3.1 Defining the XSLT Transformation Input Stream

This code can be found in buildspace\ examples\xmlstreams\xsltTransform\-XsltObjectInputStreamImp.h.

//1

The constructor for the transformation stream takes an input stream for the XML document to transform, a transformation object, and a flag to indicate whether or not the output should be escaped.

//2

Here you initialize the base class using the char transformation stream defined by the typedef above. Note that you

  • first create a character input stream,

  • then use that to create the Xalan transformation char input stream,

  • then use the Xalan char stream to create an Istream input stream,

  • and finally use that stream to create the base RWXmlObjectInputStreamImp. This is an example of chaining together streaming elements to create a new stream with specific functionality (in this case the ability to transform an XML document using XSLT).

//3

The static make() function produces an object stream handle by creating a Xalan transformation stream. Here you construct a transformation object and pass it to the constructor for the Xalan transformation stream.

6.2.3.2 Defining the XSLT Transformation Output Stream

Define the output stream in the same way.

This code can be found in buildspace\examples\xmlstreams\xsltTransform\RWXsltObjectOutputStreamImp.h.

You now have everything you need to apply XSLT transformations to the XML input or output using the Xalan XSLT engine.

The next section describes how to use these objects to perform an actual transformation.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.