<commit_before><xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
		xmlns:h="http://www.w3.org/1999/xhtml"
		xmlns="http://www.w3.org/1999/xhtml"
		exclude-result-prefixes="l">

  <!-- Global ToDo: switch logic from @class = whatever to contains(@class, 'whatever') -->

  <!-- Chunk template used to split content among multiple .html files -->

  <!-- Imports htmlbook.xsl -->
  <xsl:import href="htmlbook.xsl"/>

  <xsl:output method="xml"
              encoding="UTF-8"/>
  <xsl:preserve-space elements="*"/>

  <!-- Specify a number from 0 to 5, where 0 means chunk at top-level sections (part, chapter, appendix), and 1-5 means chunk at the corresponding sect level (sect1 - sect5) -->
  <xsl:param name="chunk.level" select="0"/>

  <!-- Specify a prefix for output filename for a given class -->
  <xsl:param name="output.filename.prefix.by.class">
appendix:app
chapter:ch
part:part
sect1:s
sect2:s
sect3:s
sect4:s
sect5:s
  </xsl:param>

  <xsl:template match="h:section|h:div[contains(@class, 'part')]|h:nav[contains(@class, 'toc')]">
    <xsl:variable name="is.chunk">
      <xsl:call-template name="is-chunk"/>
    </xsl:variable>
    <!-- <xsl:message>Element name: <xsl:value-of select="local-name()"/>, Class name: <xsl:value-of select="@class"/>, Is chunk: <xsl:value-of select="$is.chunk"/></xsl:message> -->
    <xsl:if test="$is.chunk = 1">
      <xsl:variable name="output-filename">
	<xsl:call-template name="output-filename-for-chunk"/>
      </xsl:variable>
      <!-- <xsl:message>Output filename: <xsl:value-of select="$output-filename"/></xsl:message> -->
    </xsl:if>
    <xsl:apply-imports/><commit_msg>Output logic with exsl:document, plus some todo notes.<commit_after><xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:exsl="http://exslt.org/common"
		xmlns:h="http://www.w3.org/1999/xhtml"
		xmlns="http://www.w3.org/1999/xhtml"
		extension-element-prefixes="exsl"
		exclude-result-prefixes="exsl h">

  <!-- Chunk template used to split content among multiple .html files -->

  <!-- Imports htmlbook.xsl -->
  <xsl:import href="htmlbook.xsl"/>

  <xsl:output method="xml"
              encoding="UTF-8"/>
  <xsl:preserve-space elements="*"/>

  <!-- Specify a number from 0 to 5, where 0 means chunk at top-level sections (part, chapter, appendix), and 1-5 means chunk at the corresponding sect level (sect1 - sect5) -->
  <xsl:param name="chunk.level" select="0"/>

  <!-- Specify a prefix for output filename for a given class -->
  <xsl:param name="output.filename.prefix.by.class">
appendix:app
chapter:ch
part:part
sect1:s
sect2:s
sect3:s
sect4:s
sect5:s
  </xsl:param>

  <!-- Specify an output directory for chunked files; otherwise defaults to current directory -->
  <!-- Todo: deal with situation where nested exsl:document calls change context directory on which relative filepaths are based, resulting in nested outputdir/outputdir filenames for chunks within chunks -->
  <!-- From the docs at http://www.exslt.org/exsl/elements/document/ -->
  <!--  When the href attribute of a subsidiary document is a relative URI, the relative URI is resolved into an absolute URI only if and when the subsidiary document is output. The output URI of the document with which the subsidiary document is associated (ie the output URI of its parent in the tree of documents) is used as the base URI. The resulting absolute URI is used as the output URI of the subsidiary document. -->
  <!-- Simplest solution might just be to prepend ".." as needed -->
  <xsl:param name="outputdir"/>
       
  <xsl:template match="h:section|h:div[contains(@class, 'part')]|h:nav[contains(@class, 'toc')]">
    <xsl:variable name="is.chunk">
      <xsl:call-template name="is-chunk"/>
    </xsl:variable>
    <!-- <xsl:message>Element name: <xsl:value-of select="local-name()"/>, Class name: <xsl:value-of select="@class"/>, Is chunk: <xsl:value-of select="$is.chunk"/></xsl:message> -->
    <xsl:choose>
      <xsl:when test="$is.chunk = 1">
	<xsl:variable name="output-filename">
	  <xsl:call-template name="output-filename-for-chunk"/>
	</xsl:variable>
	<!-- <xsl:message>Output filename: <xsl:value-of select="$output-filename"/></xsl:message> -->
	<xsl:variable name="full-output-filename">
	  <xsl:if test="$outputdir != ''">
	    <xsl:value-of select="concat($outputdir, '/')"/>
	  </xsl:if>
	  <xsl:value-of select="$output-filename"/>
	</xsl:variable>
	<xsl:message>Full output filename: <xsl:value-of select="$full-output-filename"/></xsl:message>
	<exsl:document href="{$full-output-filename}" method="xml">
	  <!-- ToDo: Add DocType, <head>, <body>, any other postprocessing, etc., logic here -->
	  <xsl:apply-imports/>
	</exsl:document>
      </xsl:when>
      <xsl:otherwise>
	<xsl:apply-imports/>
      </xsl:otherwise>
    </xsl:choose>
{'fraction_non_alphanumeric': 0.17511708409692528, 'fraction_numerical': 0.013846467114640602, 'mean_word_length': 3.9267803410230693, 'pattern_counts': {'":': 0, '<': 91, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 7, 'xml': 12}, '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': '1320699', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1545, 'n_words': 408}