Q:

Transforming nested XML elements to equal parent element; remove parent

I have a piece of XML that looks as follows:
<LISTOFHARDWARE>
    <HARDWARE>
        <item>
            <SERIALNUMBER>D4242050101</SERIALNUMBER>
            <STATUS>2 </STATUS>
            <STATUSREASON>998 </STATUSREASON>
            <MACADDRESS />
            <LINKEDSMARTCARD>4135237101</LINKEDSMARTCARD>
            <PRODUCTDETAIL>
                <TYPE>DEVICE</TYPE>
                <MODEL>ABC123</MODEL>
            </PRODUCTDETAIL>
        </item>
        <item>
            <SERIALNUMBER>D4242050101</SERIALNUMBER>
            <STATUS>2 </STATUS>
            <STATUSREASON>998 </STATUSREASON>
            <MACADDRESS />
            <LINKEDSMARTCARD>4135237101</LINKEDSMARTCARD>
            <PRODUCTDETAIL>
                <TYPE>DEVICE</TYPE>
                <MODEL>ABC123</MODEL>
            </PRODUCTDETAIL>
        </item>
    </HARDWARE>
</LISTOFHARDWARE>   

I would like the <item> elements to be replaced by <HARDWARE> elements (the immediate parent element), and the parent <HARDWARE> element to be removed, so that the result looks as follows:
<LISTOFHARDWARE>
    <HARDWARE>
        <SERIALNUMBER>D4242050101</SERIALNUMBER>
        <STATUS>2 </STATUS>
        <STATUSREASON>998 </STATUSREASON>
        <MACADDRESS />
        <LINKEDSMARTCARD>4135237101</LINKEDSMARTCARD>
        <PRODUCTDETAIL>
            <TYPE>DEVICE</TYPE>
            <MODEL>ABC123</MODEL>
        </PRODUCTDETAIL>
    </HARDWARE>
    <HARDWARE>
        <SERIALNUMBER>D4242050101</SERIALNUMBER>
        <STATUS>2 </STATUS>
        <STATUSREASON>998 </STATUSREASON>
        <MACADDRESS />
        <LINKEDSMARTCARD>4135237101</LINKEDSMARTCARD>
        <PRODUCTDETAIL>
            <TYPE>DEVICE</TYPE>
            <MODEL>ABC123</MODEL>
        </PRODUCTDETAIL>

    </HARDWARE>
</LISTOFHARDWARE>   

Is there a way I can do this in an XSL transformation that will work for any XML file that contains <item> elements?
EDIT
After the help on this answer and a little further research, I am almost there, but not quite. Consider the following:
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>

    <!--  Replace <item> with name of parent element -->
    <xsl:template match="item">
        <xsl:element name="{name(..)}">
            <xsl:apply-templates select="@*|node()" />
        </xsl:element>
    </xsl:template>

    <!-- Remove immediate parent of <item> elements -->
    <xsl:template match="item/.."> <!-- Results in syntax error --> 
            <xsl:apply-templates select="@*|node()" />
    </xsl:template>

</xsl:stylesheet>

The problem is that after successful of changing the <item> elements to the name of the parent, I cannot remove the parent of any item element by referencing its parent dynamically.

A:

Here is one way of doing it: 
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <!-- Identity transform -->
  <xsl:template match=" @* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:template>

  <!-- Process any element that has "item" as child -->
  <xsl:template match="*[item]">
    <xsl:apply-templates/>
  </xsl:template>

  <!-- Replace "item" with its parent in source XML -->
  <xsl:template match="item">
    <xsl:element name="{name(..)}">
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>

A:

What about this?
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" indent="yes" />

    <xsl:template match="/*">
        <xsl:element name="{node-name(.)}">
            <xsl:for-each select="*/item">
                <xsl:element name="{node-name(..)}">
                  <xsl:copy-of select="./*" />
                </xsl:element>
            </xsl:for-each>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

EDIT BY OP: For my case, I had to change the function node-name() to name(), otherwise it wouldn't compile.

