<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.
-->

<!-- $Id: sitetree2nav.xsl 153044 2005-02-09 09:32:59Z michi $ -->

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:tree="http://apache.org/cocoon/lenya/sitetree/1.0"
    xmlns:nav="http://apache.org/cocoon/lenya/navigation/1.0"
    exclude-result-prefixes="tree">

  <xsl:param name="chosenlanguage"/>
  <xsl:param name="defaultlanguage"/>
  <xsl:param name="currentPath"/>
  
  <!-- force a specific extension for node URLs -->
  <xsl:param name="extension"/>


  <xsl:template match="tree:fragment">
    <nav:fragment>
      <xsl:copy-of select="@*"/>
      <xsl:choose>
        <xsl:when test="@base">
          <xsl:apply-templates>
            <xsl:with-param name="parentPath" select="@base"/>
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>
    </nav:fragment>
  </xsl:template>


  <xsl:template match="tree:site">
    <nav:site>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
    </nav:site>
  </xsl:template>


<!--
Resolves the existing language of a node, preferrably
the default language.
-->
  <xsl:template name="resolve-existing-language">
    <xsl:choose>
      <xsl:when test="tree:label[lang($chosenlanguage)]">
        <xsl:value-of select="$chosenlanguage"/>
      </xsl:when>
      <xsl:when test="tree:label[lang($defaultlanguage)]">
        <xsl:value-of select="$defaultlanguage"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="tree:label/@xml:lang"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


<!--
Apply nodes recursively
-->
  <xsl:template match="tree:node[not(@visible = 'false')]">

    <!-- base path of parent node -->
    <xsl:param name="parentPath" select="''"/>

    <xsl:variable name="existinglanguage">
      <xsl:call-template name="resolve-existing-language"/>
    </xsl:variable>

    <nav:node>

      <xsl:copy-of select="@id"/>
      <xsl:copy-of select="@visibleinnav"/>
      <xsl:copy-of select="@protected"/>
      <xsl:copy-of select="@folder"/>
      <xsl:copy-of select="@uuid"/>
      
      <!-- base path - for all nodes -->

      <xsl:variable name="path" select="concat($parentPath, '/', @id)"/>
      <xsl:attribute name="path"><xsl:value-of select="$path"/></xsl:attribute>

      <!-- suffix - only when @href is not present -->

      <xsl:variable name="extensionParam">
        <xsl:choose>
          <xsl:when test="$extension">
            <xsl:text>?uuid2url.extension=</xsl:text><xsl:value-of select="$extension"/>
          </xsl:when>
          <xsl:when test="@suffix">
            <xsl:text>?uuid2url.extension=</xsl:text><xsl:value-of select="@suffix"/>
          </xsl:when>
        </xsl:choose>
      </xsl:variable>

      <xsl:if test="$currentPath = $path">
        <xsl:attribute name="current">true</xsl:attribute>
      </xsl:if>

      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="@href">
            <xsl:value-of select="@href"/>
          </xsl:when>
          <xsl:when test="@uuid">
            <xsl:text>lenya-document:</xsl:text>
            <xsl:value-of select="@uuid"/>
            <xsl:value-of select="$extensionParam"/>
          </xsl:when>
        </xsl:choose>
      </xsl:attribute>

      <xsl:if test="@mimetype">
        <xsl:attribute name="mimetype">
          <xsl:value-of select="@mimetype"/>
        </xsl:attribute>
      </xsl:if>

      <xsl:choose>
        <xsl:when test="tree:label[lang($existinglanguage)]">
          <xsl:apply-templates select="tree:label[lang($existinglanguage)]"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="tree:label[1]"/>
        </xsl:otherwise>
      </xsl:choose>

      <xsl:apply-templates select="tree:node">
        <xsl:with-param name="parentPath" select="$path"/>
      </xsl:apply-templates>

    </nav:node>
  </xsl:template>
<commit_msg>Add area parameter to sitetree node URLs. This fixes bug 42877.<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.
-->

<!-- $Id: sitetree2nav.xsl 153044 2005-02-09 09:32:59Z michi $ -->

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:tree="http://apache.org/cocoon/lenya/sitetree/1.0"
    xmlns:nav="http://apache.org/cocoon/lenya/navigation/1.0"
    exclude-result-prefixes="tree">

  <xsl:param name="chosenlanguage"/>
  <xsl:param name="defaultlanguage"/>
  <xsl:param name="currentPath"/>
  
  <!-- force a specific extension for node URLs -->
  <xsl:param name="extension"/>


  <xsl:template match="tree:fragment">
    <nav:fragment>
      <xsl:copy-of select="@*"/>
      <xsl:choose>
        <xsl:when test="@base">
          <xsl:apply-templates>
            <xsl:with-param name="parentPath" select="@base"/>
          </xsl:apply-templates>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>
    </nav:fragment>
  </xsl:template>


  <xsl:template match="tree:site">
    <nav:site>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
    </nav:site>
  </xsl:template>


<!--
Resolves the existing language of a node, preferrably
the default language.
-->
  <xsl:template name="resolve-existing-language">
    <xsl:choose>
      <xsl:when test="tree:label[lang($chosenlanguage)]">
        <xsl:value-of select="$chosenlanguage"/>
      </xsl:when>
      <xsl:when test="tree:label[lang($defaultlanguage)]">
        <xsl:value-of select="$defaultlanguage"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="tree:label/@xml:lang"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


<!--
Apply nodes recursively
-->
  <xsl:template match="tree:node[not(@visible = 'false')]">

    <!-- base path of parent node -->
    <xsl:param name="parentPath" select="''"/>

    <xsl:variable name="existinglanguage">
      <xsl:call-template name="resolve-existing-language"/>
    </xsl:variable>

    <nav:node>

      <xsl:copy-of select="@id"/>
      <xsl:copy-of select="@visibleinnav"/>
      <xsl:copy-of select="@protected"/>
      <xsl:copy-of select="@folder"/>
      <xsl:copy-of select="@uuid"/>
      
      <!-- base path - for all nodes -->

      <xsl:variable name="path" select="concat($parentPath, '/', @id)"/>
      <xsl:attribute name="path"><xsl:value-of select="$path"/></xsl:attribute>

      <!-- suffix - only when @href is not present -->

      <xsl:variable name="extensionParam">
        <xsl:choose>
          <xsl:when test="$extension">
            <xsl:text>?uuid2url.extension=</xsl:text><xsl:value-of select="$extension"/>
          </xsl:when>
          <xsl:when test="@suffix">
            <xsl:text>?uuid2url.extension=</xsl:text><xsl:value-of select="@suffix"/>
          </xsl:when>
        </xsl:choose>
      </xsl:variable>
      
      <xsl:variable name="area" select="ancestor::tree:fragment/@area"/>
      <xsl:variable name="areaParam">
        <xsl:if test="$area">
          <xsl:text>,area=</xsl:text><xsl:value-of select="$area"/>
        </xsl:if>
      </xsl:variable>

      <xsl:if test="$currentPath = $path">
        <xsl:attribute name="current">true</xsl:attribute>
      </xsl:if>

      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="@href">
            <xsl:value-of select="@href"/>
          </xsl:when>
          <xsl:when test="@uuid">
            <xsl:text>lenya-document:</xsl:text>
            <xsl:value-of select="@uuid"/>
            <xsl:value-of select="$areaParam"/>
            <xsl:value-of select="$extensionParam"/>
          </xsl:when>
        </xsl:choose>
      </xsl:attribute>

      <xsl:if test="@mimetype">
        <xsl:attribute name="mimetype">
          <xsl:value-of select="@mimetype"/>
        </xsl:attribute>
      </xsl:if>

      <xsl:choose>
        <xsl:when test="tree:label[lang($existinglanguage)]">
          <xsl:apply-templates select="tree:label[lang($existinglanguage)]"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="tree:label[1]"/>
        </xsl:otherwise>
      </xsl:choose>

      <xsl:apply-templates select="tree:node">
        <xsl:with-param name="parentPath" select="$path"/>
      </xsl:apply-templates>

    </nav:node>
  </xsl:template>

{'fraction_non_alphanumeric': 0.16983586869495595, 'fraction_numerical': 0.008907125700560448, 'mean_word_length': 2.831671779141104, 'pattern_counts': {'":': 0, '<': 236, '<?xml version=': 2, '>': 236, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 10}, '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': '6536526', 'n_tokens_mistral': 3370, 'n_tokens_neox': 3011, 'n_words': 653}