Show TOC

XML TransformationLocate this document in the navigation structure

Use

XML transformation is done with XSL and SAX transformers. With the transformation service you define the transformers once and then use them in combination with already defined transformers without the need to redefine them before transforming.

Transformation can be done on registered transformers only. Registered transformers can also be used by other content developers using the XML iView user interface from the portal.

Combining several transformers to generate one output is called pipe transformation. Pipe transformation allows you to develop light-weight transformers and connect them to one powerful transformer.

The following table lists the transformer attributes exposed by the ITransformerInformation interface.

Attribute

Type

Description

Name

String (cs)

The name of the transformer; has to be unique for an application component

Component name

String (cs)

The name of the portal component or portal service that registered the transformer

Version

Float

The version of the transformer. Using the correct version number helps to avoid errors when a transformer is upgraded.

Transformer type

TransformerType

Registration type of the transformer can be one of the following:

  • Built-in

    Transformer was provided by the transformation service.

  • Persistent

    Transformer was supplied by transformation provider (see Providing Transformers )

  • Temporary

    Transformer is temporarily supplied from a regular portal application

From scheme

String (cs)

XML input format: a scheme from which the transformer gets the XML data

To scheme

String (cs)

XML output format: defines the output format of the transformer

Description

String

General description of the transformer

Activation

To activate a XML transformation, perform the following tasks:

  1. Create a transformer list

    To get related transformers information according to the attributes, pass the requested attributes as parameters to the getTransformersInformation() method. Call this method for each transformer you want to add. The method returns all transformers that match the specified attribute.

  2. Define parameters

    Create an array of the same size as the transformer list. Every item in the array must be a map of parameters related to the transformer with the same index.

  3. Generate the XML source

    Generate the XML source to be transformed. See XML Source for more details.

  4. Generate the XML result

    Generate the object that receives the result of the transformation. See XML Result for more details.

  5. Activate transformation

    Call the transform() method of the service.

XML Source

The implementation of the XML source must inherit from javax.xml.transform.Source . The XML input can be file, stream, DOM or another customized class. The source classes provided by the JDK are:

  • javax.xml.transform.stream.StreamSource

  • javax.xml.transform.sax.SAXSource

  • javax.xml.transform.dom.DOMSource

The HTTPStreamSource class, an addition of the transformation service, is used for working with URL-based XML sources that use the portal cache, proxy settings and PCD attributes to load XML files from the Web. It is strongly recommended to work with this class when loading XML files from the Web. For more information, see the class definition in the transformation service Javadoc and examples.

XML Result

The implementation of the XML result must inherit from javax.xml.transform.result . The supplied class keeps the result of the transformation in the format specified by the last transformer in the transformation pipe. Result classes provided by the JDK are:

  • javax.xml.transform.stream.StreamResult

  • javax.xml.transform.sax.SAXResult

  • javax.xml.transform.dom.DOMResult

Result Types

There are the following types of XML transformation results:

  • IPortalComponentResponse

    To ensure that the results are written directly to the response of the portal component, create a new StreamResult object with the response writer.

    Sample Code
        …
        // Setting result stream 
        StreamResult strmResult = new StreamResult(response.getWriter());
        // Transforming 
        tService.transform(src,trns, paramsArr, context, null, strmRes);
        …
    
                         
  • HTML-B

    The result of the transformation performed by the XHTMLB transformer is a set of HTML-B objects. By default, you create this set of objects in the page context, however it is possible to specify that the result should be rendered to the response by parameters. For more information, see Built-in Transformers .

  • String

    To ensure that the results are written to a string, create a StreamResult object with a ByteArrayOutputStream as its constructor input field. After the transformation, retrieve the string from the created ByteArrayOutputStream object.

    Sample Code
    OutputStream outStrm = new ByteArrayOutputStream(); 
        StreamResult strm = new StreamResult(outStrm);
        tService.transform(source, trns, params, context, null, strm); 
        ... 
        String result = outStrm.toString();