TEIC / TEI

The Text Encoding Initiative Guidelines
https://www.tei-c.org
Other
269 stars 88 forks source link

How are we to refer to an `<egXML>`? (Or `<figure>` or `<table>`?) #2332

Open sydb opened 1 year ago

sydb commented 1 year ago

The CMC folks wanted to refer, from within a paragraph of prose, to one of the examples in the chapter. Turns out, though, if you just do the reasonable, expected thing (put an @xml:id on the <egXML>, and then refer to it with a <ptr>), the output looks awful. (Because the text of the pointer is created by concatenating all the text nodes in the target.) That is a Stylesheets problem (for which there is not yet an issue). BUT it begs the question “how do we normally do this?”.

The answer is, we don’t have a normal way to do this. As far as I can tell (using the XSLT below):

below

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:tei="http://www.tei-c.org/ns/1.0"
  version="3.0">

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:text>&#x0A; </xsl:text>
    <xsl:apply-templates select="//tei:*/@target[starts-with( normalize-space(.), '#')]"/>
  </xsl:template>

  <xsl:template match="@target">
    <xsl:variable name="whatIamTargetOf" select="local-name(..)" as="xs:string"/>
    <xsl:variable name="whereIpoint" select="substring( normalize-space( .), 2 )" as="xs:string"/>
    <xsl:variable name="whatIpointAt" select="local-name( id( $whereIpoint ) )" as="xs:string"/>
    <xsl:variable name="whichOccurence" as="xs:string">
      <xsl:number select=".." level="single" ordinal="yes"/>
    </xsl:variable>
    <xsl:if test="not( $whatIpointAt = ('div', 'specGrp', 'bibl', 'biblStruct') )">
      <xsl:sequence select="  $whatIamTargetOf
                            ||'/@target='
                            ||$whereIpoint
                            ||' points to a '
                            ||local-name( id( $whereIpoint ) )
                            ||'; it is in section '
                            ||(ancestor-or-self::*[@xml:id|@ident][1]/@xml:id|ancestor-or-self::*[@xml:id|@ident][1]/@ident)[1]
                            ||' and is the '
                            ||$whichOccurence
                            ||' such.&#x0A;'
        "/>
      <!-- Note-to-self: That run-on XPath for the section selects an
           @xml:id preferentially over an @ident. That is not really
           what we want; we want whichever is closer. Not worth the
           effort at the moment, especially since it turns out there
           is only 1 that does not have in @xml:id. -->
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>