format XML tag content.

Hello,

I have an small xml but with a single tag with text as long as 3 pages, I need to now is there a way to format this text inside the extraction variable of the tag, like Line CR:LF bold, paragraph, format spaces and tables, all the tag is variable and is text of a contract.

example:

https://learn.objectiflune.com/qa-blobs/13971871503479060647.xml

Download Example

Not sure how you want to format the content of the tag but i have created the attached example which demonstrates how you could approach this task. In the data mapper, I’m splitting the text on the LF (\n). Once I have this array of lines,

var tc = data.extract('./evc_spc_endoso_emision7[1]/txt_anexo[1]').split('\n');
var numLines = tc.length;

I can now use the technique described here to extract each line as a separate record in a detail table.

In the Extraction within the Repeat loop, I can then test for the line I am on; i.e whether it’s a header, subheader or simply a paragraph. In this example, I have formatted the headers and subheaders with the following script:

let currentLine = tc[parseInt(steps.currentLoopCounter)-1];
let newCurrentLine ='';

if(currentLine.trim() == 'POLIZA DE ACCIDENTES PERSONALES INDIVIDUALES'){
	newCurrentLine = '<h3>' + currentLine + '</h3>';
}else if(currentLine.trim() == 'CONDICIONES GENERALES' ){
	newCurrentLine = '<h4>' + currentLine + '</h4>';
}else if(/^[0-9].*$/.test(currentLine)){
	newCurrentLine = '<h5>' + currentLine + '</h5>';
}else{
	currentLine;
}

Now in the Designer, it’s just a matter of inserting a detail table. Then select the field @t2@, right-click and click on Text…Format the whitespace attribute with the pre-wrap value so that the formatting of the text is maintained while automatically adding line breaks.

The result is as follow:

Hopefully, you can build on this example to format the other types of lines or even remove empty lines where desired.

1 Like

Thanks a lot, this resolve my issue.