Page 1 of 1

XSLTOperation replacing the root element not working

Posted: Mon Feb 24, 2014 3:13 pm
by Patrik
Hi,

I want to apply an XSLTOperation on the root element replacing the previous one. I don't get any error messages but the content is not being replaced.

I guess there is a special behavior required in TransformOperation for the case that the root node needs to be replaced instead of the following lines:

Code: Select all

// Put the result of the XSLT transformation back into the document.
if (ACTION_REPLACE.equals(action)) {
authorAccess.getDocumentController().insertXMLFragment(result, targetNode, ACTION_INSERT_BEFORE);
authorAccess.getDocumentController().deleteNode(targetNode);
} else [...]
Is there any easy way I can fix this behavior?

Thanks and regards,

Patrik

Re: XSLTOperation replacing the root element not working

Posted: Mon Feb 24, 2014 5:53 pm
by alex_jitianu
Hi Patrik,

Right now the only way to fix this behavior is to create your own custom XSLTOperation. You should start from the source code of the default operation and replace the code you indicated with something like this:

Code: Select all


// Put the result of the XSLT transformation back into the document.
if (ACTION_REPLACE.equals(action)) {
if (targetNode.getParent().getType() == AuthorNode.NODE_TYPE_DOCUMENT) {
AuthorDocumentFragment authorFragment = authorAccess.getDocumentController().createNewDocumentFragmentInContext(
result,
targetNode.getStartOffset());
// Root replace.
authorAccess.getDocumentController().replaceRoot(authorFragment);
} else {
authorAccess.getDocumentController().insertXMLFragment(
result, targetNode, ACTION_INSERT_BEFORE);
authorAccess.getDocumentController().deleteNode(targetNode);
}
}
We will make the same change ourselves so the fix will be available in the next release.

Best regards,
Alex

Re: XSLTOperation replacing the root element not working

Posted: Tue Feb 25, 2014 9:08 am
by Patrik
Hi Alex,

thanks alot - it worked on the first try. :)

Regards,

Patrik