我正在使用一个必须符合 TEI 的 XML 文件。问题在于 pb(分页符)里程碑。这不是一个新问题,但现有的解决方案是如此复杂和繁重,以至于我想知道在我的案例中是否有更简单的方法。
让我们拥有这个 XML 文件部分:
<body>
<pb n="2"/><p>Some random text is put here</p><p>Another
paragraph starts here, and in the
middle of it<pb n="3"/> a page break occurred.</p><pb n="4"/
<p>the next paragraph begins
on a new page</p>
<p>But in the next paragraph, after<pb n="5"/>another page break, something else
happend : a note<note
type=glossary">the note content</note> and so everything
failing <pb n="6"/> because of this note.
我想将 XML 转换成这个 HTML:
<table>
<tr><td><p>Some random text is put here</p><p>Another paragraph starts here, and in the
middle of it</p></td><td>2</td></tr>
<tr><td><p>a page break occurred.</p></td><td>3</td></tr>
<tr><td><p>the next par graph begins on a new page</p></td><td>4</td></tr>
<tr><td><p>But in the next paragraph, after</td><td>5</td></tr>
<tr><td><p>another page break, something else happend : a note
<note type=glossary">the note content</note> and so everything's failing</td><td>6</td></tr>
<tr><td>because of this note.</td></tr>
在我看来,应该可以很简单地通过一个 for-each-group 来实现。所以,基本上,我正在尝试这样的事情:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="/body">
<table>
<xsl:for-each-group select="descendant::*" group-starting-with="pb">
<tr><td><xsl:value-of select="current-group()"/>
</td><td><xsl:value-of select="current-group()[1]/@n"/>
</td></tr>
</xsl:for-each-group>
</table>
</xsl:template>
</xsl:stylesheet>
显然,它不起作用......结果是:
<table><tr><td> Some random text is put here Another paragraph starts here, and in the
middle of it a page break occurred.</td><td>2</td></tr>
<tr><td/><td>3</td></tr><tr><td>
the next paragraph begins on
a new page</td><td>4</td></tr></table>
我是不是走错了方向?
非常感谢您的帮助 !克里斯托夫