<?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/pasta" />
</xsl:template>


<xsl:template match="pasta">
  <xsl:choose>
	  <xsl:when test="count(./*) &gt; 0">
		<li><xsl:call-template name="item2"/>
		<ul>
		<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>
		</ul>
		</li>
	  </xsl:when>

	  <xsl:otherwise>
		<li><xsl:call-template name="item2"/></li>
	  </xsl:otherwise>
  </xsl:choose>
</xsl:template>



<xsl:template match="pag">
  <xsl:call-template name="item"/>
</xsl:template>


<xsl:template name="item">
  <xsl:if test="not( normalize-space(../text()) = normalize-space(./text()) )">
	<li><xsl:call-template name="item2"/></li>
  </xsl:if>
</xsl:template>


<xsl:template name="item2">
  <xsl:variable name="aux2"><xsl:choose>
		<xsl:when test="@id_pagina">id_pagina=<xsl:value-of select="@id_pagina"/><xsl:if test="@assoc=1">&amp;assoc=<xsl:value-of select="@assoc"/>&amp;id_pasta=<xsl:value-of select="../@id_pasta"/></xsl:if></xsl:when>
		<xsl:otherwise>id_pasta=<xsl:value-of select="@id_pasta"/></xsl:otherwise>
	</xsl:choose></xsl:variable>
  <xsl:variable name="aux3">_X_URL_X_?<xsl:value-of select="normalize-space($aux2)"/></xsl:variable>
  <xsl:if test="not( normalize-space(../text()) = normalize-space(./text()) )">
  	<a href="{$aux3}" class="_X_ACLASS_X_"><xsl:value-of select="normalize-space(text())" /></a>
  </xsl:if>
</xsl:template>


</xsl:stylesheet>


