Copying Shape In fom one document to another position of the shape is not maintained

Since shapes are convert to images while converting docx to HTML and back to docx. I am programitically adding unique id to each shape’s alternative text in the source document . When it is converted to Word again from HTML these shapes are images in the word . Then i programatically iterate through each shap in the new document and copy actual shape from the source document using alternative text as key and then remove the image from the target document . All this works fine but for some reason some shape is not maintaining it’s position in the target document same as source. See the screenshot below

Below is the function that copies the shape from source to target and removes the images which were origianlly converted from shape (textbox etc)

public void CopyShapes(ref Document doc, Document template)
{
    List<Node> docShapeNodes = doc.GetChildNodes(NodeType.Shape, true).Where(s => ((Shape)s).AlternativeText.StartsWith("#shape#~")).ToList();
    foreach (Node docShapeNode in docShapeNodes)
    {
        Shape docShape = (Shape)docShapeNode;
        string shapeid = docShape.AlternativeText;
        List<Node> templateShapeNodes = template.GetChildNodes(NodeType.Shape, true).Where(s => ((Shape)s).AlternativeText.Contains(shapeid)).ToList();
        if (templateShapeNodes.Count > 0)
        {
            Shape templateShape = (Shape)templateShapeNodes[0];
            Paragraph para = (Paragraph)docShape.ParentParagraph;
            NodeImporter nodeImporter = new NodeImporter(template, doc, ImportFormatMode.KeepSourceFormatting);
            Shape docShape_FromTemplate = (Shape)nodeImporter.ImportNode(templateShape, true);

            para.InsertAfter(docShape_FromTemplate, docShape);//, docShape);
            docShape_FromTemplate.ZOrder = templateShape.ZOrder;

            docShape.Remove();
        }
    }
}

Can you please provide me how i can preserve postions as orginal document
Have also uploaded the in and out filesin.docx (6.9 MB)
out-rountrip.docx (6.3 MB)

@cyrusdaru1
It is difficult to outline the exact cause of the issue because of the attached files do not match the sample code ("#shape#~" prefix for AltText is empty).
Apparently, the first part of the issue

is the incorrect match of “#shape#~” prefixes, the textbox is positioned correctly, and the purple background represented by a separate shape is shifted.

The second part of the issue

is that the bottom textbox has vertical relative positioning and it is anchored to ContentControl paragraph that doesn’t exist in the original “in.docx” document.