Q:

XSLT:Generic way to move child node to parent node in XML

I have this following xml structure:
<root>
  <p1>
    <a>1</a>
    <b>2</b>
    <_timestamp>20160928201109</_timestamp>
    <c>
    <_c_timestamp>20160928201056</_c_timestamp>Tmp</c>
  </p1>
  <p2>
    <a>1</a>
    <b>2</b>
    <_timestamp>20160928201109</_timestamp>
    <d>
    <_d_timestamp>20160928201056</_d_timestamp>Tmp1</d>
  </p2>
</root>

and want to convert to this structure using XSLT:
<root>
  <p1>
    <a>1</a>
    <b>2</b>
    <_timestamp>20160928201109</_timestamp>
    <_c_timestamp>20160928201056</_c_timestamp>
    <c>Tmp</c>
  </p1>
  <p2>
    <a>1</a>
    <b>2</b>
    <_timestamp>20160928201109</_timestamp>
    <_d_timestamp>20160928201056</_d_timestamp>
    <d>Tmp1</d>
  </p2>
</root>

i.e., any occurrence of tag with structure <_anyName_timestamp> should be moved to parent node. 
Any pointers to the XSLT structure would be helpful.

A:

any occurrence of tag with structure <_anyName_timestamp> should be
  moved to parent node.

Moving is the easy part here. The difficult part is to identify the elements to move. Try:
XSLT 1.0
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="*">
    <xsl:apply-templates select="*[starts-with(name(), '_') and contains(substring(name(), 2), '_timestamp')]"/>
    <xsl:copy>
        <xsl:apply-templates select="node()[not(starts-with(name(), '_') and contains(substring(name(), 2), '_timestamp'))]"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

Or perhaps a bit more elegant:
<xsl:template match="*">
    <xsl:variable name="ts" select="*[starts-with(name(), '_') and contains(substring(name(), 2), '_timestamp')]" />
    <xsl:apply-templates select="$ts"/>
    <xsl:copy>
        <xsl:apply-templates select="node()[count(.|$ts) > count($ts)]"/>
    </xsl:copy>
</xsl:template>

