psoTransform & the ampersand

I am using the following code block to transform an assembly item, it works great until I run into content that contains an ampersand. Seems that it return’s an empty string when the transform occurs.

$user.psoTransform.transform($rx.doc.extractBody($sys.asm.assemble($user.psoListTools.asList($asmItem)).get(0).toResultString()),'file:rx_resources/stylesheets/RemoveEditLiveFormatting.xsl')

So I dug into the percussion console output and found:

ERROR:The entity name must immediately follow the '&' in the entity reference

Sounds like I need to tweak something in the extractBody portion of the code to pre-format the output before it gets to the transform anyone have a suggestion on how to pre-format the &'s?

$rx.doc.extractBody($sys.asm.assemble($user.psoListTools.asList($asmItem)).get(0).toResultString()).replaceAll('\s&\s','
& ')

Seems to work although it may not take into account all circumstances where the ampersand is used.

Found this in the integration guide $rx.codec.escapeForXml() seems like the right tool for the job

Seemed like the right tool, but it’s not. I had to go back to the replace all method the escape will as it states turn everything into encoded xml.