You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TEI XML转HTML的XSLT开发求助:元素选择与转换失败

TEI转HTML的XSLT问题解决思路

核心问题排查与实现方案

1. standOff元素数据获取失败

  • 优先检查路径匹配:如果standOff是根节点直接子元素,需使用绝对路径/TEI/standOff/*而非相对路径;若TEI文档带命名空间,必须在XSLT头部声明并绑定对应前缀(如xmlns:tei="http://www.tei-c.org/ns/1.0"),后续调用时带上前缀
  • 用<xsl:key>建立索引关联:standOff内的元素通常通过xml:id与主文档关联,可提前定义键值实现快速调用:
    <xsl:key name="standoff-items" match="tei:standOff//*" use="@xml:id"/>
    
    后续通过key('standoff-items', @ref)即可获取对应节点数据

2. note转HTML脚注实现

  • 编写模板匹配note节点,生成页面内引用与底部脚注:
    <!-- 匹配正文中的note,生成上标引用 -->
    <xsl:template match="tei:note">
      <sup id="note-ref-{@xml:id}">
        <a href="#note-body-{@xml:id}"><xsl:value-of select="@n"/></a>
      </sup>
      <!-- 将脚注内容暂存,后续输出到页面底部 -->
      <xsl:variable name="note-data" select="."/>
      <xsl:call-template name="collect-footnote">
        <xsl:with-param name="id" select="@xml:id"/>
        <xsl:with-param name="content" select="$note-data"/>
      </xsl:call-template>
    </xsl:template>
    
    <!-- 定义脚注收集模板 -->
    <xsl:template name="collect-footnote">
      <xsl:param name="id"/>
      <xsl:param name="content"/>
      <xsl:if test="not($footnote-collected[$id])">
        <xsl:variable name="new-footnotes" select="$footnote-collected | $id"/>
        <xsl:variable name="new-footnote-contents" select="$footnote-contents | $content"/>
        <xsl:call-template name="collect-footnote">
          <xsl:with-param name="id" select="$id"/>
          <xsl:with-param name="content" select="$content"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:template>
    
    <!-- 在页面底部输出所有脚注 -->
    <xsl:template match="/tei:TEI">
      <!-- 其他转换内容 -->
      <div class="footnotes">
        <hr/>
        <h3>脚注</h3>
        <ol>
          <xsl:for-each select="$footnote-contents">
            <li id="note-body-{@xml:id}">
              <xsl:copy-of select="node()"/>
              <a href="#note-ref-{@xml:id}">↩</a>
            </li>
          </xsl:for-each>
        </ol>
      </div>
    </xsl:template>
    

3. rs元素转链接实现

  • 根据rs的ref属性生成页面内或外部链接,若关联standOff数据则结合键值索引:
    <xsl:key name="rs-target" match="tei:standOff//tei:persName | tei:standOff//tei:placeName" use="@xml:id"/>
    
    <xsl:template match="tei:rs">
      <a href="#{@ref}" 
         title="{if (key('rs-target', @ref)) then key('rs-target', @ref)/@fullName else ''}">
        <xsl:value-of select="."/>
      </a>
    </xsl:template>
    

补充要求

请提供你的完整TEI XML源码和现有XSLT代码片段,方便定位命名空间冲突、路径匹配错误等细节问题。

内容的提问来源于stack exchange,提问作者Jaap

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 04:46:03