13. Display navigation menu

xsl:stylesheet id="stylesheet" exclude-result-prefixes="x2 lit xs" version="1.0" xml:lang="en"

xsl:key name="labels" match="xs:label" use="@href"
xsl:key name="html-uris" match="xs:html-uri" use="@href"

display navigation
site-map-doc parameter
site-map parameter
nl
li
number
label
all elements
number
label
auto-nav all
auto-nav section
auto-nav text
auto-nav root

xsl:param name="site-map" id="site-map" select="'#DOES-NOT-EXIST'"
xsl:param name="site-map-doc" id="site-map-doc" select="document($site-map)"
xsl:template name="display-navigation" id="display-navigation"
  xsl:choose
    xsl:when test="count($site-map-doc)>0"
      xsl:apply-templates select="$site-map-doc/x2:html/x2:body/x2:nl" mode="navigation"
    
    xsl:otherwise
      xsl:apply-templates select="/" mode="auto-nav"
    
  
xsl:template match="x2:section" mode="auto-nav" id="auto-nav.section"
  <li>
    <a>
      xsl:attribute name="href"
        xsl:text#
        xsl:call-template name="id"
      
      xsl:apply-templates select="x2:h/node()"
    </a>

    xsl:if test="x2:section"
      <ul class="navigation">
        xsl:apply-templates mode="auto-nav"
      </ul>
    
  </li>
xsl:template match="text()" mode="auto-nav" id="auto-nav.text"
xsl:template match="/" mode="auto-nav" id="auto-nav.root"
  <ul class="navigation">
    xsl:apply-templates mode="auto-nav"
  </ul>
xsl:template match="*" mode="auto-nav" id="auto-nav.all"
  xsl:apply-templates mode="auto-nav"
xsl:template match="xs:label" id="label"
xsl:template match="xs:number" id="number"