Expand | Collapse

◀ 14. XHTML1 pass-through16. Manipulating URIs ▶

15. Display navigation menu

This stylesheet is responsible for displaying the navigation pane, that is visible for example in this HTML documentation.

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"
  xsl:key name="site-items" match="xs:site-item" use="@href"
  xsl:param name="site-map" select="'#DOES-NOT-EXIST'"
  xsl:param name="site-map-doc" select="document($site-map)"

  display-navigation template

  xsl:template match="xs:label"
  xsl:template match="xs:number"

  Navigation menu using site maps
  Navigation menu without site maps
  Page navigation in body pane
  Links to related pages in HTML head

15.1. display-navigation template

As with automatic numbering, there needs to be implemented two versions of the navigation pane: one when a site map is active, and the other for stand-alone single-file documents. The following template selects from one of the two approaches:

xsl:template name="display-navigation"
        xsl:when test="count($site-map-doc)>0"
          <ul class="_navigation">
            xsl:apply-templates select="$site-map-doc/xs:site-map/xs:site-item" mode="navigation-from-site-map"
          xsl:apply-templates select="/" mode="navigation"

15.2. Navigation menu using site maps

xsl:template match="node()" mode="navigation-from-site-map"
xsl:template match="xs:site-item" mode="navigation-from-site-map"
            xsl:attribute name="href"
              xsl:call-template name="map-uri"
                xsl:with-param name="href" select="@href"
            xsl:apply-templates select="xs:title[1]" mode="title-text"
          xsl:if test="xs:site-item"
            <ul class="_navigation">
              xsl:apply-templates select="xs:site-item" mode="navigation-from-site-map"

15.3. Navigation menu without site maps

The navigation mode creates a navigation menu based on the nesting of sections in the current XML document only.

xsl:template match="x2:section" mode="navigation"
            xsl:attribute name="href"
              xsl:call-template name="id"
            xsl:apply-templates select="x2:h" mode="title-text"
          xsl:if test="x2:section"
            <ul class="_navigation">
              xsl:apply-templates mode="navigation"
xsl:template match="text()" mode="navigation"
xsl:template match="/" mode="navigation"
        <ul class="_navigation">
          xsl:apply-templates mode="navigation"
xsl:template match="*" mode="navigation"
        xsl:apply-templates mode="navigation"

15.5. Links to related pages in HTML head

This is similar to Page navigation in body pane above, but the pages are exposed as link elements inside the HTML head. These links may be used by web spiders, or special navigation functionality in web browsers.

15.5.1. output-page-link-item: outputs one link in head

xsl:template name="output-page-link-item"
        xsl:param name="target"
        xsl:param name="relation"
        xsl:param name="title"
          xsl:apply-templates select="$target/xs:title[1]" mode="title-text"
        xsl:if test="count($target) > 0"
          <link rel="{$relation}" title="{$title}">
            xsl:attribute name="href"
              xsl:call-template name="map-uri"
                xsl:with-param name="href" select="$target/@href"

15.5.2. output-page-links: outputs links in head

xsl:template name="output-page-links"

        xsl:variable name="uri"
          xsl:call-template name="absolute-uri"

        xsl:for-each select="$site-map-doc"
          Get the site map nodes

          xsl:call-template name="output-page-link-item"
            xsl:with-param name="relation" select="'previous'"
            xsl:with-param name="target" select="$previous"

          xsl:call-template name="output-page-link-item"
            xsl:with-param name="relation" select="'up'"
            xsl:with-param name="target" select="$up"

          xsl:call-template name="output-page-link-item"
            xsl:with-param name="relation" select="'next'"
            xsl:with-param name="target" select="$next"


Formatted using xhtml2to1 by Steve Cheng.