<commit_before><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:related-links="http://dita-ot.sourceforge.net/ns/200709/related-links"
    exclude-result-prefixes="related-links xs">

  <xsl:key name="link"
           match="*[contains(@class, ' topic/link ')][not(ancestor::*[contains(@class, ' topic/linklist ')])]"
           use="related-links:link(.)"/>
  <xsl:key name="hideduplicates"
           match="*[contains(@class, ' topic/link ')][not(ancestor::*[contains(@class, ' topic/linklist ')])]
                   [empty(@role) or @role = ('cousin', 'external', 'friend', 'other', 'sample', 'sibling')]"
           use="related-links:hideduplicates(.)"/>

  <xsl:function name="related-links:omit-from-unordered-links" as="xs:boolean">
    <xsl:param name="node" as="element()"/>
    <xsl:sequence select="$node/@role = ('child', 'descendant', 'next', 'previous', 'parent') or
                          $node[@importance = 'required' and (empty(@role) or @role = ('sibling', 'friend', 'cousin'))] or
                          $node/ancestor::*[contains(@class, ' topic/linklist ')]"/>
  </xsl:function>
  
  <xsl:function name="related-links:hideduplicates" as="xs:string">
    <xsl:param name="link" as="element()"/>
    <xsl:value-of select="concat($link/ancestor::*[contains(@class, ' topic/related-links ')]/parent::*[contains(@class, ' topic/topic ')]/@id,
                                 ' ',
                                 $link/@href,
                                 $link/@scope,
                                 $link/@audience,
                                 $link/@platform,
                                 $link/@product,
                                 $link/@otherprops,
                                 $link/@rev,
                                 $link/@type,
                                 normalize-space(string-join($link/*, ' ')))"/>
  </xsl:function>
  
  <xsl:function name="related-links:link" as="xs:string">
    <xsl:param name="link" as="element()"/>
    <xsl:value-of select="concat($link/ancestor::*[contains(@class, ' topic/related-links ')]/parent::*[contains(@class, ' topic/topic ')]/@id,
                                 ' ',
                                 $link/@href,
                                 $link/@type,
                                 $link/@role,
                                 $link/@platform,
                                 $link/@audience,
                                 $link/@importance,
                                 $link/@outputclass,
                                 $link/@keyref,
                                 $link/@scope,
                                 $link/@format,
                                 $link/@otherrole,
                                 $link/@product,
                                 $link/@otherprops,
                                 $link/@rev,
                                 $link/@class,
                                 $link/../@collection-type,
                                 normalize-space(string-join($link/*, ' ')))"/>
  </xsl:function>

    <!-- Ungrouped links have a priority of zero.  (Can be overridden.) -->
    <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:get-group-priority"
        name="related-links:group-priority." as="xs:integer">
        <xsl:sequence select="0"/>
    </xsl:template>

    <!-- Ungrouped links belong to the no-name group.  (Can be overridden.)  -->
    <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:get-group" name="related-links:group." as="xs:string">
        <xsl:text/>
    </xsl:template>

    <!-- Without a group, links are emitted as-is.  (Can be overridden.) -->
    <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:result-group"
                  name="related-links:group-result." as="element(linklist)">
        <xsl:param name="links" as="node()*"/>
        <xsl:if test="normalize-space(string-join($links, ''))">
          <linklist class="- topic/linklist " outputclass="relinfo relref">
            <xsl:sequence select="$links"/>
          </linklist>
        </xsl:if>
    </xsl:template>

    <!-- Ungrouped links have the default-mode template applied to them. (Can be overridden.) -->
    <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:link" name="related-links:link."
                  as="element(link)">
      <xsl:sequence select="."/>
    </xsl:template>

    <!-- Main entry point. -->
    <xsl:template match="*[contains(@class, ' topic/related-links ')]" mode="related-links:group-unordered-links"
                  as="element(linklist)*">
        <!-- Node set.  The set of nodes to group. -->
        <xsl:param name="nodes" as="element()*"/>
        <!-- Sent back to all callback templates as a parameter.-->
        <!-- XXX: Seems obsolete as the value is never used anywhere -->
        <xsl:param name="tunnel"/>

        <!-- Query all links for their group and priority. -->
        <xsl:variable name="group-priorities" as="xs:string">
            <xsl:call-template name="related-links:get-priorities"><commit_msg>Allow specializations of the link element #2199<commit_after><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:related-links="http://dita-ot.sourceforge.net/ns/200709/related-links"
    exclude-result-prefixes="related-links xs">

  <xsl:key name="link"
           match="*[contains(@class, ' topic/link ')][not(ancestor::*[contains(@class, ' topic/linklist ')])]"
           use="related-links:link(.)"/>
  <xsl:key name="hideduplicates"
           match="*[contains(@class, ' topic/link ')][not(ancestor::*[contains(@class, ' topic/linklist ')])]
                   [empty(@role) or @role = ('cousin', 'external', 'friend', 'other', 'sample', 'sibling')]"
           use="related-links:hideduplicates(.)"/>

  <xsl:function name="related-links:omit-from-unordered-links" as="xs:boolean">
    <xsl:param name="node" as="element()"/>
    <xsl:sequence select="$node/@role = ('child', 'descendant', 'next', 'previous', 'parent') or
                          $node[@importance = 'required' and (empty(@role) or @role = ('sibling', 'friend', 'cousin'))] or
                          $node/ancestor::*[contains(@class, ' topic/linklist ')]"/>
  </xsl:function>
  
  <xsl:function name="related-links:hideduplicates" as="xs:string">
    <xsl:param name="link" as="element()"/>
    <xsl:value-of select="concat($link/ancestor::*[contains(@class, ' topic/related-links ')]/parent::*[contains(@class, ' topic/topic ')]/@id,
                                 ' ',
                                 $link/@href,
                                 $link/@scope,
                                 $link/@audience,
                                 $link/@platform,
                                 $link/@product,
                                 $link/@otherprops,
                                 $link/@rev,
                                 $link/@type,
                                 normalize-space(string-join($link/*, ' ')))"/>
  </xsl:function>
  
  <xsl:function name="related-links:link" as="xs:string">
    <xsl:param name="link" as="element()"/>
    <xsl:value-of select="concat($link/ancestor::*[contains(@class, ' topic/related-links ')]/parent::*[contains(@class, ' topic/topic ')]/@id,
                                 ' ',
                                 $link/@href,
                                 $link/@type,
                                 $link/@role,
                                 $link/@platform,
                                 $link/@audience,
                                 $link/@importance,
                                 $link/@outputclass,
                                 $link/@keyref,
                                 $link/@scope,
                                 $link/@format,
                                 $link/@otherrole,
                                 $link/@product,
                                 $link/@otherprops,
                                 $link/@rev,
                                 $link/@class,
                                 $link/../@collection-type,
                                 normalize-space(string-join($link/*, ' ')))"/>
  </xsl:function>

    <!-- Ungrouped links have a priority of zero.  (Can be overridden.) -->
    <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:get-group-priority"
        name="related-links:group-priority." as="xs:integer">
        <xsl:sequence select="0"/>
    </xsl:template>

    <!-- Ungrouped links belong to the no-name group.  (Can be overridden.)  -->
    <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:get-group" name="related-links:group." as="xs:string">
        <xsl:text/>
    </xsl:template>

    <!-- Without a group, links are emitted as-is.  (Can be overridden.) -->
    <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:result-group"
                  name="related-links:group-result." as="element(linklist)">
        <xsl:param name="links" as="node()*"/>
        <xsl:if test="normalize-space(string-join($links, ''))">
          <linklist class="- topic/linklist " outputclass="relinfo relref">
            <xsl:sequence select="$links"/>
          </linklist>
        </xsl:if>
    </xsl:template>

    <!-- Ungrouped links have the default-mode template applied to them. (Can be overridden.) -->
    <xsl:template match="*[contains(@class, ' topic/link ')]" mode="related-links:link" name="related-links:link"
                  as="element()*">
      <xsl:sequence select="."/>
    </xsl:template>

    <!-- Main entry point. -->
    <xsl:template match="*[contains(@class, ' topic/related-links ')]" mode="related-links:group-unordered-links"
                  as="element(linklist)*">
        <!-- Node set.  The set of nodes to group. -->
        <xsl:param name="nodes" as="element()*"/>
        <!-- Sent back to all callback templates as a parameter.-->
        <!-- XXX: Seems obsolete as the value is never used anywhere -->
        <xsl:param name="tunnel"/>

        <!-- Query all links for their group and priority. -->
        <xsl:variable name="group-priorities" as="xs:string">
            <xsl:call-template name="related-links:get-priorities">
{'fraction_non_alphanumeric': 0.1751182592242195, 'fraction_numerical': 0.004541154210028382, 'mean_word_length': 1.7980412916887243, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 2, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6799646', 'n_tokens_mistral': 3122, 'n_tokens_neox': 2910, 'n_words': 513}