Skip to content

Commit

Permalink
IDs for app elements.
Browse files Browse the repository at this point in the history
Fixes #294
  • Loading branch information
thvitt committed Feb 14, 2018
1 parent 1dddbd2 commit c68c2d4
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions xslt/text-insert-app.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,38 @@
<xsl:apply-templates mode="pass2" select="$inserted-apps"/>
</xsl:template>

<!-- calculates an id for the seg corresponding to an app's f:ins -->
<xsl:function name="f:seg-id" as="xs:string">
<!-- base function for the id calculations, based in an app's f:ins -->
<xsl:function name="f:ins-id" as="xs:string">
<xsl:param name="prefix" as="xs:string"/>
<xsl:param name="ins" as="element(f:ins)"/>
<xsl:variable name="parts" as="item()*">
<xsl:for-each select="$ins">
<xsl:for-each select="$ins"><!-- focus -->
<xsl:variable name="strrep" select="replace(lower-case(.), '\W+', '')"/>
<xsl:text>lem</xsl:text>
<xsl:value-of select="$prefix"/>
<xsl:value-of select="@n"/>
<xsl:choose>
<xsl:when test="$strrep != ''"><xsl:value-of select="$strrep"/></xsl:when>
<xsl:when test="@place"><xsl:value-of select="@place"/></xsl:when>
<xsl:otherwise><xsl:value-of select="count($ins/../preceding::app)"/></xsl:otherwise>
<xsl:when test="@place"><xsl:value-of select="@place"/></xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="string-join($parts, '.')"/>
</xsl:function>

<!-- calculates an id for the seg corresponding to an app's f:ins -->
<xsl:function name="f:seg-id" as="xs:string">
<xsl:param name="ins" as="element(f:ins)"/>
<xsl:value-of select="f:ins-id('seg', $ins)"/>
</xsl:function>

<!-- calculates an id for an app -->
<xsl:function name="f:app-id" as="xs:string">
<xsl:param name="for" as="node()"/>
<xsl:variable name="app" select="$for/ancestor-or-self::app[1]"/>
<xsl:variable name="ins" select="$app/f:ins[1]"/>
<xsl:value-of select="f:ins-id('app', $ins)"/>
</xsl:function>


<!-- lines for which an apparatus entry exists -->
<xsl:template match="*[f:hasvars(.)][tokenize(@n, '\s+') = $spec//f:ins/@n]">
Expand All @@ -66,13 +80,15 @@
</xsl:for-each>
</xsl:template>

<!-- creates the note[@type="textcrit"] for the givven app element -->
<!-- creates the note[@type="textcrit"] for the given app element -->
<xsl:template name="create-app-note">
<xsl:param name="apps"/>
<xsl:for-each select="$apps">
<note type="textcrit">
<xsl:attribute name="xml:id" select="f:app-id(.)"/>
<xsl:copy-of select="ref" copy-namespaces="no"/>
<app from="#{f:seg-id(f:ins[1])}">
<app>
<xsl:attribute name="from" select="for $ins in f:ins return concat('#', f:seg-id($ins))" separator=" "/>
<xsl:apply-templates select="lem" mode="app"/>
<xsl:apply-templates select="rdg" mode="app"/>
</app>
Expand Down

0 comments on commit c68c2d4

Please sign in to comment.