<commit_before><?xml version="1.0" encoding="utf-8"?>
<!--
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
-->

<xsl:stylesheet
  version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:df="http://dita2indesign.org/dita/functions" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:relpath="http://dita2indesign/functions/relpath"
  xmlns:htmlutil="http://dita4publishers.org/functions/htmlutil"
  xmlns:index-terms="http://dita4publishers.org/index-terms"
  xmlns:glossdata="http://dita4publishers.org/glossdata"
  xmlns:mapdriven="http://dita4publishers.org/mapdriven"
  xmlns:enum="http://dita4publishers.org/enumerables"
  xmlns:local="urn:functions:local"
  exclude-result-prefixes="local xs df xsl relpath htmlutil index-terms mapdriven glossdata enum">

  <xsl:template name="navigation">
    <xsl:param name="navigation" as="element()*"  tunnel="yes" />
    <xsl:param name="is-root" as="xs:boolean"  tunnel="yes" select="false()" />
    <xsl:param name="resultUri" as="xs:string" tunnel="yes" select="''" />
    <xsl:if test="$OUTPUTDEFAULTNAVIGATION and $is-root = false()">
    <xsl:variable name="navigation-fixed">
      <xsl:apply-templates select="$navigation" mode="fix-navigation-href">
        <xsl:with-param name="resultUri" select="$resultUri" />
      </xsl:apply-templates>
    </xsl:variable>
    <xsl:sequence select="$navigation-fixed"/>
    </xsl:if>
  </xsl:template>

  <!--
    choose navigation markup type
    will be used later to offer alternate markup for navigation
   -->
  <xsl:template match="*" mode="choose-html5-nav-markup">
    <xsl:param name="is-root" as="xs:boolean" tunnel="yes" select="false()" />
    <xsl:message> + [INFO] Generating HTML5 <xsl:value-of select="$NAVIGATIONMARKUP"/> navigation</xsl:message>
    <xsl:apply-templates select="." mode="generate-html5-nav-page-markup"/>
  </xsl:template>

  <xsl:template match="*[df:class(., 'map/map')]" mode="generate-html5-nav">
    <xsl:param name="collected-data" as="element()" tunnel="yes"/>

    <xsl:message> + [INFO] Generating HTML5 navigation structure...</xsl:message>

    <xsl:apply-templates mode="generate-html5-nav"/>

    <xsl:if test="$generateIndexBoolean">
      <xsl:apply-templates mode="generate-html5-nav" select="$collected-data">
        <xsl:with-param name="parentId" select="'root'" as="xs:string" tunnel="yes"/>
      </xsl:apply-templates>
    </xsl:if>

    <xsl:message> + [INFO] HTML5 navigation generation done.</xsl:message>
  </xsl:template>

  <xsl:template mode="generate-html5-nav-page-markup" match="*[df:class(., 'map/map')]">
    <xsl:param name="collected-data" as="element()" tunnel="yes"/>
    <xsl:param name="documentation-title" tunnel="yes" />
    <xsl:param name="is-root" as="xs:boolean" tunnel="yes" select="false()" />
    <xsl:param name="showTocEntry" as="xs:boolean" tunnel="yes" select="false()" />

    <nav id="{$IDLOCALNAV}" role="navigation" aria-label="Main navigation">
      <xsl:attribute name="class" select="$CLASSNAVIGATION"/>

        <div id="nav-content">

          <xsl:variable name="listItems" as="node()*">
            <xsl:apply-templates mode="generate-html5-nav"
              select=".
              except (
              *[df:class(., 'topic/title')],
              *[df:class(., 'map/topicmeta')],
              *[df:class(., 'map/reltable')]
              )"
            />
          </xsl:variable>

        <xsl:if test="$listItems">
          <ul>
            <xsl:if test="$showTocEntry">
              <li class="toc_link">
                <a href="index.html">
                  <xsl:call-template name="getString">
                    <xsl:with-param name="stringName" select="'TOC'"/>
                  </xsl:call-template>
                </a>
              </li>
            </xsl:if>
            <xsl:sequence select="$listItems"/>
          </ul>
        </xsl:if>
      </div>
    </nav>
  </xsl:template>

  <xsl:template mode="generate-html5-nav-page-markup" match="*[df:class(., 'topic/title')][not(@toc = 'no')]">
    <h2 class="nav-pub-title">
      <xsl:apply-templates/>
    </h2>
  </xsl:template>

  <xsl:template mode="generate-html5-nav" match="*[df:class(., 'topic/title')][not(@toc = 'no')]"/>

  <!-- Convert each topicref to a ToC entry. -->
  <xsl:template  mode="generate-html5-nav" 
                 match="*[df:isTopicRef(.)]
                           [not(@processing-role = 'resource-only')]
                           [not(@toc = 'no')]
                           [not(@format) or @format = ('dita')]
                           [not(@scope) or not(string(@scope) = ('peer', 'external'))]">
    <xsl:param name="tocDepth" as="xs:integer" tunnel="yes" select="0"/>
    <xsl:param name="rootMapDocUrl" as="xs:string" tunnel="yes"/>
    <xsl:param name="isChunkedMap" as="xs:boolean" select="false()" tunnel="yes"/>
    <xsl:param name="indexUri" as="xs:string" select="''" tunnel = "yes" />
    
    <xsl:if test="$tocDepth le $maxTocDepthInt">
      <xsl:variable name="topic" select="df:resolveTopicRef(.)" as="element()*"/>
      <xsl:choose>
        <xsl:when test="not($topic)">
          <xsl:message> + [WARNING] generate-html5-nav: Failed to resolve topic reference to href
              "<xsl:sequence select="string(@href)"/>"</xsl:message>
        </xsl:when>
        <xsl:otherwise>
          <xsl:variable name="targetUri"
            select="if($isChunkedMap) then concat($outdir, '#', df:getIdForElement(.)) else htmlutil:getTopicResultUrl($outdir, root($topic), $rootMapDocUrl)"
            as="xs:string"/>
          <xsl:variable name="relativeUri" select="relpath:getRelativePath($outdir, $targetUri)"
            as="xs:string"/>
          <xsl:variable name="enumeration" as="xs:string?">
            <xsl:apply-templates select="." mode="enumeration"/>
          </xsl:variable>
          <xsl:variable name="self" select="generate-id(.)" as="xs:string"/>

          <!-- Use UL for navigation structure -->

          <li>
            <a href="{$relativeUri}">
              <!-- target="{$contenttarget}" -->
              <xsl:if test="$enumeration and $enumeration != ''">
                <span class="enumeration enumeration{$tocDepth}">
                  <xsl:sequence select="$enumeration"/>
                </span><commit_msg>Output hash when availaible<commit_after><?xml version="1.0" encoding="utf-8"?>
<!--
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
-->

<xsl:stylesheet
  version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:df="http://dita2indesign.org/dita/functions" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:relpath="http://dita2indesign/functions/relpath"
  xmlns:htmlutil="http://dita4publishers.org/functions/htmlutil"
  xmlns:index-terms="http://dita4publishers.org/index-terms"
  xmlns:glossdata="http://dita4publishers.org/glossdata"
  xmlns:mapdriven="http://dita4publishers.org/mapdriven"
  xmlns:enum="http://dita4publishers.org/enumerables"
  xmlns:local="urn:functions:local"
  exclude-result-prefixes="local xs df xsl relpath htmlutil index-terms mapdriven glossdata enum">

  <xsl:template name="navigation">
    <xsl:param name="navigation" as="element()*"  tunnel="yes" />
    <xsl:param name="is-root" as="xs:boolean"  tunnel="yes" select="false()" />
    <xsl:param name="resultUri" as="xs:string" tunnel="yes" select="''" />
    <xsl:if test="$OUTPUTDEFAULTNAVIGATION and $is-root = false()">
    <xsl:variable name="navigation-fixed">
      <xsl:apply-templates select="$navigation" mode="fix-navigation-href">
        <xsl:with-param name="resultUri" select="$resultUri" />
      </xsl:apply-templates>
    </xsl:variable>
    <xsl:sequence select="$navigation-fixed"/>
    </xsl:if>
  </xsl:template>

  <!--
    choose navigation markup type
    will be used later to offer alternate markup for navigation
   -->
  <xsl:template match="*" mode="choose-html5-nav-markup">
    <xsl:param name="is-root" as="xs:boolean" tunnel="yes" select="false()" />
    <xsl:message> + [INFO] Generating HTML5 <xsl:value-of select="$NAVIGATIONMARKUP"/> navigation</xsl:message>
    <xsl:apply-templates select="." mode="generate-html5-nav-page-markup"/>
  </xsl:template>

  <xsl:template match="*[df:class(., 'map/map')]" mode="generate-html5-nav">
    <xsl:param name="collected-data" as="element()" tunnel="yes"/>

    <xsl:message> + [INFO] Generating HTML5 navigation structure...</xsl:message>

    <xsl:apply-templates mode="generate-html5-nav"/>

    <xsl:if test="$generateIndexBoolean">
      <xsl:apply-templates mode="generate-html5-nav" select="$collected-data">
        <xsl:with-param name="parentId" select="'root'" as="xs:string" tunnel="yes"/>
      </xsl:apply-templates>
    </xsl:if>

    <xsl:message> + [INFO] HTML5 navigation generation done.</xsl:message>
  </xsl:template>

  <xsl:template mode="generate-html5-nav-page-markup" match="*[df:class(., 'map/map')]">
    <xsl:param name="collected-data" as="element()" tunnel="yes"/>
    <xsl:param name="documentation-title" tunnel="yes" />
    <xsl:param name="is-root" as="xs:boolean" tunnel="yes" select="false()" />
    <xsl:param name="showTocEntry" as="xs:boolean" tunnel="yes" select="false()" />

    <nav id="{$IDLOCALNAV}" role="navigation" aria-label="Main navigation">
      <xsl:attribute name="class" select="$CLASSNAVIGATION"/>

        <div id="nav-content">

          <xsl:variable name="listItems" as="node()*">
            <xsl:apply-templates mode="generate-html5-nav"
              select=".
              except (
              *[df:class(., 'topic/title')],
              *[df:class(., 'map/topicmeta')],
              *[df:class(., 'map/reltable')]
              )"
            />
          </xsl:variable>

        <xsl:if test="$listItems">
          <ul>
            <xsl:if test="$showTocEntry">
              <li class="toc_link">
                <a href="index.html">
                  <xsl:call-template name="getString">
                    <xsl:with-param name="stringName" select="'TOC'"/>
                  </xsl:call-template>
                </a>
              </li>
            </xsl:if>
            <xsl:sequence select="$listItems"/>
          </ul>
        </xsl:if>
      </div>
    </nav>
  </xsl:template>

  <xsl:template mode="generate-html5-nav-page-markup" match="*[df:class(., 'topic/title')][not(@toc = 'no')]">
    <h2 class="nav-pub-title">
      <xsl:apply-templates/>
    </h2>
  </xsl:template>

  <xsl:template mode="generate-html5-nav" match="*[df:class(., 'topic/title')][not(@toc = 'no')]"/>

  <!-- Convert each topicref to a ToC entry. -->
  <xsl:template  mode="generate-html5-nav"
                 match="*[df:isTopicRef(.)]
                           [not(@processing-role = 'resource-only')]
                           [not(@toc = 'no')]
                           [not(@format) or @format = ('dita')]
                           [not(@scope) or not(string(@scope) = ('peer', 'external'))]">
    <xsl:param name="tocDepth" as="xs:integer" tunnel="yes" select="0"/>
    <xsl:param name="rootMapDocUrl" as="xs:string" tunnel="yes"/>
    <xsl:param name="isChunkedMap" as="xs:boolean" select="false()" tunnel="yes"/>
    <xsl:param name="indexUri" as="xs:string" select="''" tunnel = "yes" />

    <xsl:if test="$tocDepth le $maxTocDepthInt">
      <xsl:variable name="topic" select="df:resolveTopicRef(.)" as="element()*"/>
      <xsl:choose>
        <xsl:when test="not($topic)">
          <xsl:message> + [WARNING] generate-html5-nav: Failed to resolve topic reference to href
              "<xsl:sequence select="string(@href)"/>"</xsl:message>
        </xsl:when>
        <xsl:otherwise>
          <xsl:variable name="targetUri"
            select="if($isChunkedMap) then concat($outdir, '#', df:getIdForElement(.)) else concat(htmlutil:getTopicResultUrl($outdir, root($topic), $rootMapDocUrl), '#', df:getIdForElement(.))"
            as="xs:string"/>
          <xsl:variable name="relativeUri" select="relpath:getRelativePath($outdir, $targetUri)"
            as="xs:string"/>
          <xsl:variable name="enumeration" as="xs:string?">
            <xsl:apply-templates select="." mode="enumeration"/>
          </xsl:variable>
          <xsl:variable name="self" select="generate-id(.)" as="xs:string"/>

          <!-- Use UL for navigation structure -->

          <li>
            <a href="{$relativeUri}">
              <!-- target="{$contenttarget}" -->
              <xsl:if test="$enumeration and $enumeration != ''">
                <span class="enumeration enumeration{$tocDepth}">
                  <xsl:sequence select="$enumeration"/>
                </span>
{'fraction_non_alphanumeric': 0.17381838612262096, 'fraction_numerical': 0.006039749982442587, 'mean_word_length': 2.9577543079488606, 'pattern_counts': {'":': 0, '<': 203, '<?xml version=': 2, '>': 203, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2808907', 'n_tokens_mistral': 4586, 'n_tokens_neox': 4282, 'n_words': 881}