while (iterator.hasNext()) {
scripts.add(iterator.next().<SVGScriptElement>cast());
}
for (SVGScriptElement script : scripts) {
// Reparent the script subtree under a fresh script node
SVGScriptElement newScript = new OMSVGScriptElement().getElement().<SVGScriptElement>cast();
Node node;
while((node = script.getFirstChild()) != null) {
newScript.appendChild(script.removeChild(node));
}
script.getParentNode().replaceChild(newScript, script);