所以这里有一个更复杂的 XML 示例,其中也包括重叠问题。
<div type='subdivision'>
<p>
....
<anchor xml:id="AJH-L.2.63"/>intellectus cum re que sentitur <anchor
xml:id="AJH-L.2.64"/>in<anchor xml:id="AJH-L.2.65"/> apprehensione<anchor
xml:id="AJH-L.2.66"/>
....
</p>
....
<app from="#AJH-L.2.64" to="#AJH-L.2.65">
<rdg wit="#H #M #N #P #R #V">-</rdg>
</app>
<app from="#AJH-L.2.63" to="#AJH-L.2.66">
<rdg wit="#M">- <emph rend="italic">hom.</emph></rdg>
</app>
....
</div>
到目前为止我的 XSLT 模板:
<xsl:template match="TEI:anchor">
<xsl:variable select="@xml:id" name="anchorId"/>
<xsl:for-each select="ancestor::TEI:p/TEI:app[@to=concat('#',$anchorId)]">
<a class="rs" name="rs_{count(preceding::TEI:app)+1}"
href="#app_{count(preceding::TEI:app)+1}">
<xsl:value-of select="count(preceding::TEI:app)+1"/>
</a>
</xsl:for-each>
</xsl:template>
<xsl:template match="TEI:app">
<xsl:variable select="substring(@from,2)" name="from"/>
<xsl:variable select="substring(@to,2)" name="to"/>
<table class="appEntry">
<tr rowspan="{count(TEI:rdg)+1}">
<td>
<a name="app_{position()}" href="#rs_{position()}">
<xsl:value-of select="position()"/>
</a>
</td>
<td>
<!-- the referenced text from between the anchors -->
<xsl:value-of select="//TEI:div[current()]//text()[preceding::TEI:anchor[@xml:id=$from] and following::TEI:anchor[@xml:id=$to]]"/>
<xsl:for-each select="TEI:rdg">
<tr>
<td>
<!-- all readings -->
<xsl:value-of select="."/>
</td>
</tr>
</xsl:for-each>
</td>
</tr>
</table>
</xsl:template>
结果输出应如下所示:
<div class="maintext">
....
intellectus cum re que sentitur in <a href="#app_32" name="rs_32" class="rs">32</a>
apprehensione <a href="#app_33" name="rs_33" class="rs">33</a>
....
</div>
<div class="apparatus">
....
<tr>
<td><a href="#rs_32" name="app_32">32</a><td>
<td>in</td>
<td> - </td>
</tr>
<tr>
<td><a href="#rs_33" name="app_33">33</a><td>
<td>intellectus cum re que sentitur </td>
<td>- hom.</td>
</tr>
....
</div>
除了混乱的桌子,这似乎工作正常。一旦我做出了正确的开始,这并不是想象中的巫毒教。
我希望,我也可以指定我的问题并给出一个好的答案。你怎么看?
问候,蒂莫