Expand | Collapse

◀ 20.4. Motivation for the xhtml2to1 linkage model▲ 20. Site maps

20.5. Processing site maps

This is site-map.xsl.
xsl:stylesheet id="stylesheet" exclude-result-prefixes="lit #default" version="1.0" xml:lang="en"
  
    xsl:output method="xml"
  
    xsl:include href="uri.xsl"
    xsl:include href="xsltsl-uri.xsl"
    xsl:include href="xref-index.xsl"
    xsl:include href="indexing.xsl"
  
    Default mode
    Auto-navigation mode
    Source-to-output URI mapping
  
  

20.5.1. Default mode

The default mode is the first mode invoked when processing a XHTML2 document. It performs the following tasks

  1. Create labels for the document and all elements with ID occurring inside the document. This task is delegated to the auto-label mode.
  2. Create section titles and section numberings for each sub-section occurring inside the document. This task is delegated to the auto-nav mode.
  3. Finally, navigate through XHTML2 sub-documents pointed to by navigation lists marked up by x2:nl.
xsl:template match="/"
        <hs:site-map>
          <hs:title>
            xsl:copy-of select="x2:html/x2:head/x2:title/node()"
          </hs:title>

          xsl:apply-templates
            xsl:with-param name="base-uri" select="$doc-uri"
          
        </hs:site-map>
      
xsl:template match="/*"
        xsl:param name="base-uri"
    
        <hs:label href="{$base-uri}">
          xsl:apply-templates select="/*" mode="for-site-map-label"
        </hs:label>
    
    <--

        <xsl:apply-templates select="/*" mode="auto-label">
          <xsl:with-param name="base-uri" select="$base-uri" />
        </xsl:apply-templates>
    
-->
    
        xsl:apply-templates select="//*[@id]" mode="auto-label"
          xsl:with-param name="base-uri" select="$base-uri"
        

        xsl:apply-templates select="/*" mode="index-term"
          xsl:with-param name="base-uri" select="$base-uri"
        

        xsl:apply-templates select="/" mode="auto-nav"
          xsl:with-param name="base-uri" select="$base-uri"
        
    
        xsl:apply-templates
          xsl:with-param name="base-uri" select="$base-uri"
        
        
      
xsl:template match="@*|text()"
      
xsl:template match="*"
        xsl:apply-templates
      
xsl:template match="x2:nl"
        xsl:apply-templates select="." mode="site-map-gen"
      
xsl:template match="node()" mode="site-map-gen"
      
xsl:template match="x2:nl" mode="site-map-gen"
        xsl:apply-templates mode="site-map-gen"
      
xsl:template match="x2:li" mode="site-map-gen"
        xsl:variable name="absolute-uri"
          xsl:call-template name="absolute-uri"
            xsl:with-param name="href" select="x2:a/@href"
          
        

        <hs:site-item href="{$absolute-uri}">
         
          <hs:html-uri href="{$absolute-uri}">
            xsl:attribute name="to"
              xsl:call-template name="html-uri"
                xsl:with-param name="href" select="$absolute-uri"
              
            
          </hs:html-uri>
        
          xsl:variable name="t" select="document(x2:a/@href, .)"
          xsl:if test="count($t)>0"
      
            xsl:apply-templates select="$t/*"
              xsl:with-param name="base-uri" select="$absolute-uri"
            
      
          

          xsl:apply-templates mode="site-map-gen"
        </hs:site-item>
      

20.5.2. Auto-navigation mode

Creates section titles and section numberings for each sub-section occurring inside the document. Sub-documents are not touched.

xsl:template match="x2:section" mode="auto-nav"
        xsl:param name="base-uri"
      
        xsl:variable name="content"

          <hs:number class="normal" />
          
          <hs:title>
            xsl:copy-of select="x2:h/node()"
          </hs:title>
      
          xsl:apply-templates select="x2:section" mode="auto-nav"
            xsl:with-param name="base-uri" select="$base-uri"
          
      
        
      
        xsl:choose
          xsl:when test="count( parent::* ) > 0"
            <hs:site-item>
              xsl:attribute name="href"
                xsl:call-template name="absolute-id"
                  xsl:with-param name="base" select="$base-uri"
                
              

              xsl:copy-of select="$content"
            </hs:site-item>
          
      
          xsl:otherwise
            xsl:copy-of select="$content"
          
        
      
      
xsl:template match="*" mode="auto-nav"
        xsl:param name="base-uri"
        xsl:apply-templates mode="auto-nav"
          xsl:with-param name="base-uri" select="$base-uri"
        
      
xsl:template match="@*|text()" mode="auto-nav"
      

20.5.3. Source-to-output URI mapping

html-uri implements the lower-level part of the source-to-output URI transformation.

This is the simplest implementation possible, which is renaming the xml file name extension to the html extension.

xsl:template name="html-uri"
      xsl:param name="href" select="@href"
      xsl:param name="suffix" select="'.xml'"
      xsl:param name="replacement" select="'.html'"
    
      xsl:choose
        xsl:when test="starts-with($href, '#')"
          xsl:value-of select="$href"
        
    
        xsl:when test="contains($href, '#') and contains($href, $suffix)"
          xsl:variable name="fragment" select="substring-after($href, '#')"
          xsl:variable name="doc-uri" select="substring-before($href, '#')"
    
          xsl:value-of select="concat(substring-before($doc-uri, $suffix), $replacement, '#', $fragment)"
        
        xsl:when test="contains($href, $suffix)"
          xsl:value-of select="concat(substring-before($href, $suffix), $replacement)"
        
        xsl:otherwise
          xsl:value-of select="$href"
        
      
    

Formatted using xhtml2to1 by Steve Cheng.