Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sydb opened this issue Sep 3, 2022 · 0 comments
Open

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

sydb opened this issue Sep 3, 2022 · 0 comments

Comments

@sydb
Copy link
Member

sydb commented Sep 3, 2022

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):

  • We use <ref> to point to <anchor> (makes sense, would be hard to generate link text from an empty element) — Note that this happens 5 times, and it is always the same anchor.
  • We use both <ptr> and <ref> to point to <figure> (The former 4 times; the latter twice, both the same figure.)
  • We use <ptr> to point to <table>.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants