<?xml version="1.0" encoding="ISO-8859-1" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
	<xsl:apply-templates select="menu" />
</xsl:template>


<xsl:template match="menu">
  <xsl:copy select=".">
  	<xsl:copy-of select="@*" />
	<xsl:apply-templates select="pasta|pag">
		<xsl:sort select="local-name()" order="ascending"/>
		<xsl:sort data-type="number" select="@posicao" order="ascending"/>
		<xsl:sort data-type="number" select="@n" order="ascending"/>
	</xsl:apply-templates>
  </xsl:copy>
</xsl:template>


<xsl:template match="pag">
  <xsl:call-template name="copiar"/>
</xsl:template>


<xsl:template match="pasta">
  <xsl:call-template name="copiar"/>
  <xsl:apply-templates select="pasta|pag">
		<xsl:sort select="local-name()" order="ascending"/>
		<xsl:sort data-type="number" select="@posicao" order="ascending"/>
		<xsl:sort data-type="number" select="@n" order="ascending"/>
  </xsl:apply-templates>
</xsl:template>


<xsl:template name="copiar">
  <xsl:copy select=".">
  	<xsl:copy-of select="@*" />
  	<xsl:attribute name="sn" value="mudar" />
  	<xsl:attribute name="posicao" value="mud" />
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>


