XSLTOperation replacing the root element not working

Post here questions and problems related to oXygen frameworks/document types.
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

XSLTOperation replacing the root element not working

Post 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
alex_jitianu
Posts: 1016
Joined: Wed Nov 16, 2005 11:11 am

Re: XSLTOperation replacing the root element not working

Post 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
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Re: XSLTOperation replacing the root element not working

Post by Patrik »

Hi Alex,

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

Regards,

Patrik
Post Reply