Processing rich text in RPE


One of the long term requirements we had for RPE was the ability to process/modify the detailed formatting of the data. With RPE 1.2 it is now possible to control the formatting at character level while preserving ( if so desired) all the data source formatting.

With RPE 1.2 it is possible to produce this:

The car shall be controllable in any direction.

from this:

The car shall be controllable in any direction.

With prior RPE versions you could have only gotten this ( apply the formatting to the entire data):

The car shall be controllable in any direction.

or this ( apply at character level but loose any existing formatting):

The car shall be controllable in any direction.

In other words RPE 1.2 allows you to inspect/modify the data at character level including including any formatting. Also note that you can produce XHTML data on the fly without any data coming from the data source.

Example

Processing DOORS Data shows how you can use this new feature. Related Infocenter entries:

Rich text data

Before I describe how this new feature works I want to briefly explain how RPE receives and processes the rich text data from point products. Regardless of the technology used in point products to display&store rich data ( RTF, XHTML, proprietary formatting) RPE only accepts XHTML as input.

So when XHTML  is found in the data RPE will parse and render it in a similar manner that web browsers would do it. But if the point product exports its rich text as  anything but XHTML ( RTF for example) you’ll get that as raw data in the output and not formatted data.

NOTE RPE does not support the full XHTML specification and some formatting information is not used. We are working to improve the coverage to include the most common and useful aspects of the specification so if you encounter a specific property that is not yet handled please raise an RFE though the IBM Software RFE Community.

A very simple XHTML chunk looks like this:

The car <b>shall</b> be controllable in <u>any</u> direction.

Processing XHTML

Processing XHTML is done through java Script. There are 2 new controls in the RPE Document Studio JavaScript editor that define how RPE should process the input to the script as well as its output:

XHTML Input

If this checkbox is unchecked RPE will strip any formatting information from the data properties used in the script. So for the the above example the data will be brought in the script as:

The car shall be controllable in any direction.

This is how RPE 1.1.2.2 and older worked. In this scenario any rich text formatting coming from the data source is lost and only the raw data is preserver.

But if ‘XHTML input’ is checked than the data comes in as is, including all the tags that define the rich text.

XHTML Output

Just like “XHTML Input” controls how RPE introduces the data in the script, XHTML Output controls how RPE handles the result. If this option is uncheked the behavior is identical to the one RPE 1.1.2.2 older had as the result is handled as plain text. This means that if the text has XHTML tags those will not be processed as such and the result would look like this:

The car <b>shall</b> be controllable in <u>any</u> direction.

To get RPE to actually parse the result as XHTML you need to check this option. In this case the result string is parsed and rendered as XHTML.

The car shall be controllable in any direction.

Rich text on the fly

XHTML Input and Output can be used independent of each other. When you have no input data but want to produce XHTML on the fly you write the XHTML in the JavaScript expression and select the XHTML output option:

xhtmlOnTheFly

NOTES

Generated string must be valid XML

If XHTML output is checked you MUST ensure that the script produces valid XML or the document generation will stop with an error.  The following is an example  of erroneous XML:

a < b

The correct* XML representation is:

a &lt; b

NOTE* the above string would not pass the W3 XML validation as is but RPE encapsulates the all generated strings in <xml></xml> tags so what ends up being parsed in RPE is listed below and is valid XML.

<xml>a &lt; b</xml>

Useful links:

Performance

Processing the output as XHTML requires time so you should used it only when needed. Ideally you should you isolate, using conditions, those scenarios where this functionality is mandatory. The following is an example of wasteful usage of this functionality:

xhtmlidentifyTransformationas the result is equivalent to this but duplicates the XHTML processing that RPE does.dataAttribute

Advertisements

Author: Dragos Cojocari

Architect for Rational Publishing Engine

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s