<commit_before><?xml version="1.0"?>
<!--
  Copyright 2002-2005 The Apache Software Foundation or its licensors,
  as applicable.

  Licensed 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
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:p="http://outerx.org/daisy/1.0#publisher"
    xmlns:ns="http://outerx.org/daisy/1.0"
    version="1.0">
    
  
  <!-- The path to the current document, used to calculate the path
       to the site root when working out paths in links -->
  <xsl:param name="documentPath"/>
  
  <!-- The pathPrefix is added to the start of all resolved Daisy links 
       It must include a trailing slash if it is non-empty -->
  <xsl:param name="pathPrefix">/</xsl:param>
  
  <!-- The daisyExt is added between the Daisy ID and the extension of 
        of all daisy links. If non-empty it must include a prefixing '.' -->
  <xsl:param name="daisyExt">.daisy</xsl:param>
    
  <xsl:template match="daisyDocument">
    <xsl:variable name="rootElementName"><xsl:value-of select="name(*)"/></xsl:variable>
    <html>
      <head>
        <xsl:choose>
          <xsl:when test="//ns:document">
            <title><xsl:value-of select="//ns:document/@name"/></title>
            <xsl:apply-templates select="//p:preparedDocument/ns:document/ns:fields/ns:field"/>
          </xsl:when>
          <xsl:when test="$rootElementName = 'html'">
            <title><xsl:value-of select="html/head/title"/></title>
          </xsl:when>
          <xsl:otherwise>
            <title>Daisy Error</title>
          </xsl:otherwise>
        </xsl:choose>
      </head>
      <body>
        <xsl:choose>
          <xsl:when test="$rootElementName = 'p:publisherResponse'">
            <xsl:apply-templates select="p:publisherResponse/p:document/p:preparedDocuments/p:preparedDocument[@id='1']"/>
          </xsl:when>
          <xsl:when test="$rootElementName = 'html'">
            <xsl:apply-templates select="//body"/>
          </xsl:when>
          <xsl:otherwise>
            <h1>Daisy Error</h1>
            <p>Unable to transform the daisy document with root element of <xsl:value-of select="$rootElementName"/>.</p>
          </xsl:otherwise>
        </xsl:choose>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="ns:field">
    <xsl:for-each select="ns:string">
      <meta>
        <xsl:attribute name="name"><xsl:value-of select="../@name"/></xsl:attribute>
        <xsl:attribute name="content"><xsl:value-of select="."/></xsl:attribute>
      </meta>
    </xsl:for-each>
  </xsl:template>
  
  <xsl:template match="p:preparedDocument">
    <xsl:comment>Prepared Document: ID = <xsl:value-of select="@id"/></xsl:comment>
    <xsl:apply-templates select="ns:document/ns:parts/ns:part"/>
  </xsl:template>
  
  <xsl:template match="ns:part">
    <xsl:comment>Part: Name <xsl:value-of select="@name"/></xsl:comment>
    <xsl:if test="@name!='SimpleDocumentContent'">
      <h1><xsl:value-of select="@name"/></h1>
    </xsl:if>
    <xsl:apply-templates select="html/body"/>
  </xsl:template>
  
  <xsl:template match="ns:searchResult">
    <table>
        <xsl:apply-templates/>
    </table>
  </xsl:template>
  
  <xsl:template match="ns:titles">
    <tr>
      <xsl:apply-templates/>
    </tr>
  </xsl:template>
  
  <xsl:template match="ns:title">
    <td>
      <xsl:apply-templates/>
    </td>
  </xsl:template>
  
  <xsl:template match="ns:rows">
    <xsl:apply-templates/>
  </xsl:template>
  
  <xsl:template match="ns:row">
    <tr>
      <xsl:apply-templates/>
    </tr>
  </xsl:template>
  
  <xsl:template match="ns:value">
    <td>
      <xsl:choose>
        <xsl:when test="position() = 1">
          <a>
            <xsl:attribute name="href"><xsl:value-of select="../@documentId"/>.daisy.html</xsl:attribute>
            <xsl:apply-templates/>
          </a>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>
    </td>
  </xsl:template>
  
  <xsl:template match="body">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="p:daisyPreparedInclude">
    <xsl:variable name="id" select="@id"/>
    <h1><xsl:value-of select="//p:preparedDocument[@id=$id]/ns:document/@name"/></h1>
    <xsl:apply-templates select="//p:preparedDocument[@id=$id]"/>
  </xsl:template>
  
  <xsl:template match="p[@class='note']">
    <div class="frame note">
      <div class="label">Note</div>
      <div class="content"><xsl:apply-templates/></div>
    </div>
  </xsl:template>
  
  <xsl:template match="p[@class='fixme']">
    <div class="frame fixme">
      <div class="label">Fixme</div>
      <div class="content"><xsl:apply-templates/></div>
    </div>
  </xsl:template>
  
  <xsl:template match="p[@class='warning']">
    <div class="frame warning">
      <div class="label">Warning</div><commit_msg>Update code to support daisy 1.5 due-to=<EMAIL><commit_after><?xml version="1.0"?>
<!--
  Copyright 2002-2005 The Apache Software Foundation or its licensors,
  as applicable.

  Licensed 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
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:p="http://outerx.org/daisy/1.0#publisher"
    xmlns:ns="http://outerx.org/daisy/1.0"
    version="1.0">
    
  
  <!-- The path to the current document, used to calculate the path
       to the site root when working out paths in links -->
  <xsl:param name="documentPath"/>
  
  <!-- The pathPrefix is added to the start of all resolved Daisy links 
       It must include a trailing slash if it is non-empty -->
  <xsl:param name="pathPrefix">/</xsl:param>
  
  <!-- The daisyExt is added between the Daisy ID and the extension of 
        of all daisy links. If non-empty it must include a prefixing '.' -->
  <xsl:param name="daisyExt">.daisy</xsl:param>
    
  <xsl:template match="daisyDocument">
    <xsl:variable name="rootElementName"><xsl:value-of select="name(*)"/></xsl:variable>
    <html>
      <head>
        <xsl:choose>
          <xsl:when test="//ns:document">
            <title><xsl:value-of select="//ns:document/@name"/></title>
            <xsl:apply-templates select="//p:preparedDocument//ns:document/ns:fields/ns:field"/>
          </xsl:when>
          <xsl:when test="$rootElementName = 'html'">
            <title><xsl:value-of select="html/head/title"/></title>
          </xsl:when>
          <xsl:otherwise>
            <title>Daisy Error</title>
          </xsl:otherwise>
        </xsl:choose>
      </head>
      <body>
        <xsl:choose>
          <xsl:when test="$rootElementName = 'p:publisherResponse'">
            <xsl:apply-templates select="p:publisherResponse/p:document/p:preparedDocuments/p:preparedDocument[@id='1']"/>
          </xsl:when>
          <xsl:when test="$rootElementName = 'html'">
            <xsl:apply-templates select="//body"/>
          </xsl:when>
          <xsl:otherwise>
            <h1>Daisy Error</h1>
            <p>Unable to transform the daisy document with root element of <xsl:value-of select="$rootElementName"/>.</p>
          </xsl:otherwise>
        </xsl:choose>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="ns:field">
    <xsl:for-each select="ns:string">
      <meta>
        <xsl:attribute name="name"><xsl:value-of select="../@name"/></xsl:attribute>
        <xsl:attribute name="content"><xsl:value-of select="."/></xsl:attribute>
      </meta>
    </xsl:for-each>
  </xsl:template>
  
  <xsl:template match="p:preparedDocument">
    <xsl:comment>Prepared Document: ID = <xsl:value-of select="@id"/></xsl:comment>
    <!-- Test whether the p:preparedDocument contains directly a ns:document (up to Daisy 1.4)
         or a new publisherResponse (from Daisy 1.5). -->
    <xsl:choose>
      <xsl:when test="ns:document">
        <xsl:apply-templates select="ns:document/ns:parts/ns:part"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="p:publisherResponse/ns:document/ns:parts/ns:part"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template match="ns:part">
    <xsl:comment>Part: Name <xsl:value-of select="@name"/></xsl:comment>
    <xsl:if test="@name!='SimpleDocumentContent'">
      <h1><xsl:value-of select="@name"/></h1>
    </xsl:if>
    <xsl:apply-templates select="html/body"/>
  </xsl:template>
  
  <xsl:template match="ns:searchResult">
    <table>
        <xsl:apply-templates/>
    </table>
  </xsl:template>
  
  <xsl:template match="ns:titles">
    <tr>
      <xsl:apply-templates/>
    </tr>
  </xsl:template>
  
  <xsl:template match="ns:title">
    <td>
      <xsl:apply-templates/>
    </td>
  </xsl:template>
  
  <xsl:template match="ns:rows">
    <xsl:apply-templates/>
  </xsl:template>
  
  <xsl:template match="ns:row">
    <tr>
      <xsl:apply-templates/>
    </tr>
  </xsl:template>
  
  <xsl:template match="ns:value">
    <td>
      <xsl:choose>
        <xsl:when test="position() = 1">
          <a>
            <xsl:attribute name="href"><xsl:value-of select="../@documentId"/>.daisy.html</xsl:attribute>
            <xsl:apply-templates/>
          </a>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>
    </td>
  </xsl:template>
  
  <xsl:template match="body">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="p:daisyPreparedInclude">
    <xsl:variable name="id" select="@id"/>
    <xsl:variable name="preparedDocument" select="//p:preparedDocument[@id=$id]"/>
    <h1>
      <!-- Test whether the p:preparedDocument contains directly a ns:document (up to Daisy 1.4)
           or a new publisherResponse (from Daisy 1.5). -->
      <xsl:choose>
        <xsl:when test="$preparedDocument/ns:document">
          <xsl:value-of select="$preparedDocument/ns:document/@name"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$preparedDocument/p:publisherResponse/ns:document/@name"/>
        </xsl:otherwise>
      </xsl:choose>
    </h1>
    <xsl:apply-templates select="//p:preparedDocument[@id=$id]"/>
  </xsl:template>
  
  <xsl:template match="p[@class='note']">
    <div class="frame note">
      <div class="label">Note</div>
      <div class="content"><xsl:apply-templates/></div>
    </div>
  </xsl:template>
  
  <xsl:template match="p[@class='fixme']">
    <div class="frame fixme">
      <div class="label">Fixme</div>
      <div class="content"><xsl:apply-templates/></div>
    </div>
  </xsl:template>
  
  <xsl:template match="p[@class='warning']">
    <div class="frame warning">
      <div class="label">Warning</div>
{'fraction_non_alphanumeric': 0.17203652653342522, 'fraction_numerical': 0.006547208821502412, 'mean_word_length': 2.894330761489433, 'pattern_counts': {'":': 0, '<': 331, '<?xml version=': 2, '>': 331, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 8}, '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': '4269287', 'n_tokens_mistral': 4039, 'n_tokens_neox': 3666, 'n_words': 782}