<?xml version='1.0' encoding='utf-8'?>

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
  <xsl:output indent='yes'/>
  <xsl:strip-space elements='*'/>

  <!-- match 'item' 'submenu' and 'section' tags nested inside of <menu> -->
  <xsl:template match='item[ancestor::menu]|submenu[ancestor::menu]|section[ancestor::menu]'>
    <xsl:element name='{name()}'>
      <!-- leave the 'id' attribute on the element -->
      <xsl:if test='@id'>
        <xsl:attribute name='id'>
          <xsl:value-of select='@id'/>
        </xsl:attribute>
      </xsl:if>

      <!-- convert the rest into <attribute> tags -->
      <xsl:for-each select='@*[name() != "id"]'>
        <attribute name='{name()}'>
          <xsl:if test='name() = "label"'>
            <xsl:attribute name='translatable'>yes</xsl:attribute>
          </xsl:if>
          <xsl:value-of select='.'/>
        </attribute>
      </xsl:for-each>

      <!-- process the child elements -->
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <!-- identity transform for unmatched elements/attributes -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>
