diff --git a/src/main/java/w2phtml/xhtml/ODFPageSplitter.java b/src/main/java/w2phtml/xhtml/ODFPageSplitter.java index e7c0015..db9dd90 100644 --- a/src/main/java/w2phtml/xhtml/ODFPageSplitter.java +++ b/src/main/java/w2phtml/xhtml/ODFPageSplitter.java @@ -316,7 +316,6 @@ public class ODFPageSplitter { String tableChildNodeName = tableChildNode.getNodeName(); //System.out.println("Table child node " + tableChildNodeName); if (containsSPB(tableChildNode)){ - Node tableChildFirstPart = tableChildNode.cloneNode(false); if (tableChildNodeName.equals(TEXT_SOFT_PAGE_BREAK)) { // remove inner soft page break node table.removeChild(tableChildNode); @@ -327,9 +326,9 @@ public class ODFPageSplitter { tableFirstPart.appendChild(tableChildNode.getPreviousSibling()); } } else if ( tableChildNodeName.equals(TABLE_TABLE_ROWS)) { - if (handleTableRows(tableChildFirstPart, tableChildNode)){ + if (handleTableRows(tableChildNode)){ dataMoved = true; - tableFirstPart.appendChild(tableChildFirstPart); + tableFirstPart.appendChild(tableChildNode.getPreviousSibling()); } } else if ( tableChildNodeName.equals(TABLE_TABLE_ROW)) { if (handleTableRow(tableChildNode)){ @@ -384,7 +383,6 @@ public class ODFPageSplitter { String nodeName = tableRowGroupChildNode.getNodeName(); if (containsSPB(tableRowGroupChildNode)){ - Node tableRowGroupChildFirstPart = tableRowGroupChildNode.cloneNode(false); if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)){ // remove inner soft page break node tableRowGroup.removeChild(tableRowGroupChildNode); @@ -404,9 +402,9 @@ public class ODFPageSplitter { tableRowGroupFistPart.appendChild(tableRowGroupChildNode.getPreviousSibling()); } } else if (nodeName.equals(TABLE_TABLE_ROWS)){ - if (handleTableRows(tableRowGroupChildFirstPart, tableRowGroupChildNode)){ + if (handleTableRows(tableRowGroupChildNode)){ dataMoved = true; - tableRowGroupFistPart.appendChild(tableRowGroupChildFirstPart); + tableRowGroupFistPart.appendChild(tableRowGroupChildNode.getPreviousSibling()); } } break; @@ -434,7 +432,9 @@ public class ODFPageSplitter { return dataMoved; } - private static boolean handleTableRows(Node tableRowsFistPart, Node tableRows) { + private static boolean handleTableRows(Node tableRows) { + Node tableRowsFirstPart = tableRows.cloneNode(false); + Node parent = tableRows.getParentNode(); boolean dataMoved = false; // Node counter int i = 0; @@ -446,7 +446,6 @@ public class ODFPageSplitter { String nodeName = tableRowsChildNode.getNodeName(); if (containsSPB(tableRowsChildNode)){ - Node tableRowGroupChildFirstPart = tableRowsChildNode.cloneNode(false); if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)){ // remove inner soft page break node tableRows.removeChild(tableRowsChildNode); @@ -454,12 +453,12 @@ public class ODFPageSplitter { } else if (nodeName.equals(TABLE_TABLE_ROW)){ if (handleTableRow(tableRowsChildNode)){ dataMoved = true; - tableRowsFistPart.appendChild(tableRowsChildNode.getPreviousSibling()); + tableRowsFirstPart.appendChild(tableRowsChildNode.getPreviousSibling()); } } break; } else { - tableRowsFistPart.appendChild(tableRowsChildNode); + tableRowsFirstPart.appendChild(tableRowsChildNode); dataMoved = true; } } else { @@ -470,6 +469,9 @@ public class ODFPageSplitter { } } + if (dataMoved) { + parent.insertBefore(tableRowsFirstPart, tableRows); + } return dataMoved; } private static boolean handleTableRow(Node tableRow) {