</xsl:template>
<xsl:template match="*" mode="endterm">
- <xsl:apply-templates select="./node()"/>
+ <!-- Process the children of the endterm element -->
+ <xsl:apply-templates select="child::node()"/>
</xsl:template>
<!-- ==================================================================== -->
</xsl:attribute>
</xsl:if>
- <xsl:apply-templates/>
+ <xsl:choose>
+ <xsl:when test="count(child::node()) > 0">
+ <!-- If it has content, use it -->
+ <xsl:apply-templates/>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- else look for an endterm -->
+ <xsl:choose>
+ <xsl:when test="@endterm">
+ <xsl:variable name="etargets" select="id(@endterm)"/>
+ <xsl:variable name="etarget" select="$etargets[1]"/>
+ <xsl:choose>
+ <xsl:when test="count($etarget) = 0">
+ <xsl:message>
+ <xsl:value-of select="count($etargets)"/>
+ <xsl:text>Endterm points to nonexistent ID: </xsl:text>
+ <xsl:value-of select="@endterm"/>
+ </xsl:message>
+ <xsl:text>???</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="$etarget" mode="endterm"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <xsl:message>
+ <xsl:text>Link element has no content and no Endterm. </xsl:text>
+ <xsl:text>Nothing to show in the link to </xsl:text>
+ <xsl:value-of select="$target"/>
+ </xsl:message>
+ <xsl:text>???</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
</a>
</xsl:template>