我正在编写具有这样基本结构的 TEI 文档。一章中有几个“mainText”部分;这些部分具有实际文本的单独规范化和 OCR 版本。
<div type="chapter">
<div type="mainText">
<div type="normalized">
<p>HERE COMES <lb/> SOME TEXT<lb/></p>
</div>
<div type="OCR">
<p>HERE COMES <lb/> SOME TEXT<lb/></p>
</div>
</div>
<div type="mainText">
<div type="normalized">
<p>HERE COMES <lb/> SOME TEXT<lb/></p>
</div>
<div type="OCR">
<p>HERE COMES <lb/> SOME TEXT<lb/></p>
</div>
</div>
</div>
使用 XSLT 2.0,我现在正在尝试执行以下步骤,这些步骤已经有效:
- 将每章中的 mainText-divs 替换为
<ab/>
- 将规范化和 OCR 版本替换为元素
<reg/>
和<orig/>
- 替换
<p>
为线组元素<lg>
- 在 linegroup 内部,将每个
<lb/>
以 line 元素结尾的组包装起来<l/>
我的问题如下:我想为每一行分配一个行号属性,但是在章节级别,意思是:在一个章节中有一个连续的行计数器。查看我当前使用的 xsl 模板:
<!-- replace p with linegroup -->
<xsl:template match="text//p">
<xsl:choose>
<!-- don't apply lingroup when there is nothing inside of p -->
<xsl:when test="not(node())">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<lg>
<!-- make a group out of everything inside of p, ending with a linebreak -->
<xsl:for-each-group select="node()" group-ending-with="lb">
<!-- wrap a line aroung current group -->
<l>
<!-- for line element create number, if line is in mainText -->
<xsl:attribute name="n">
<xsl:number/>
</xsl:attribute>
<xsl:apply-templates select="current-group()"/>
</l>
</xsl:for-each-group>
</lg>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- get rid if linebreak, as we don't need it anymore -->
<xsl:template match="p//lb"/>
其输出将创建行号,但在每个 mainText 元素中开始计数。会很高兴得到帮助。
最好的,多米尼卡