11. Process cross references

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"

xref
xref-label
label for a section

xsl:template match="xs:xref" id="xref"
  <a>
    xsl:attribute name="href"
      xsl:call-template name="map-uri"
    

    xsl:call-template name="xref-label"
  </a>
xsl:template name="xref-label" id="xref-label"
  xsl:param name="href" select="@href"

  xsl:variable name="absolute-href"
    xsl:call-template name="absolute-uri"
      xsl:with-param name="href" select="$href"
    
  

  xsl:choose
    xsl:when test="count($site-map-doc)>0"
      xsl:for-each select="$site-map-doc"
        xsl:apply-templates select="key('labels', $absolute-href)/node()"
      
    

    xsl:otherwise
      xsl:textunknown label
    
  

11.1. Getting the label for an element

xsl:template match="x2:section" mode="for-xref-label" id="section.for-xref-label"
  xsl:apply-templates select="x2:h/node()"