<?xml version="1.0" encoding="UTF-8"?>

<!--
   generate_module_table.xsl
   Written 2024-11-16 by Syd Bauman, based in part on modules.xsl,
   itself written 2004-10-06 by Arno Mittelbach <arno-oss@mittelbach-online.de>.

   Copyleft 2024 by Syd Bauman and the Text Encoding Initiative Consortium.

   Read in TEI P5, write out an TEI table listing the modules. The table is
   intended to be inserted into the Guidelines in section #STMA.
   
   Written to help address TEI issue 2617 <https://github.com/TEIC/TEI/issues/2617>.
-->

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.tei-c.org/ns/1.0"
  xmlns:tei="http://www.tei-c.org/ns/1.0"
  xpath-default-namespace="http://www.tei-c.org/ns/1.0"
  expand-text="yes">
  
  <xsl:output method="xml" indent="yes"/>
  
  <xsl:template match="/">
    <xsl:comment> following table generated by {static-base-uri()} at {current-dateTime()} </xsl:comment>
    <xsl:comment> based on {normalize-space(/*/teiHeader/fileDesc/editionStmt)} </xsl:comment>
    <table xml:id="tab-mods">
      <row role="label">
        <cell>Module name</cell>
        <cell>Where defined</cell>
        <cell>Formal public identifier</cell>
      </row>
      <xsl:apply-templates select="//tei:moduleSpec">
        <!-- The default sort order, document order, should get these in order by chapter # -->
      </xsl:apply-templates>
    </table>
  </xsl:template>

  <xsl:template match="tei:moduleSpec" as="element(tei:row)">
    <row>
      <cell>{@ident}</cell>
      <cell><ptr target="#{ancestor::tei:div[@xml:id][last()]/@xml:id}"/></cell>
      <cell>{tei:idno[ @type eq 'FPI']}</cell>
    </row>
  </xsl:template>

</xsl:stylesheet>
