翻訳しようとしている HTML ファイルに少し問題があります。基本的に、現在のソース構造の関連部分は次のとおりです。
<h2 />
<h3 />
<table />
<table />
<h3 />
<table />
<table />
<h3 />
<table />
<h3 />
<h3 />
<table />
<table />
<h2 />
<h3 />
...
等々。これらの各コンテンツはさまざまな方法で翻訳されていますが、現在私が抱えている問題は、それらを正しくグループ化することです。本質的に、私はそれが次のように終わることを望みます:
<category>
<h2 />
<container>
<h3 />
<table />
<table />
</container>
<container>
<h3 />
<table />
<table />
</container>
<container>
<h3 />
<table />
</container>
<container>
<h3 />
</container>
<container>
<h3 />
<table />
<table />
</container>
</category>
<category>
<h2 />
<container>
<h3 />
...
これを実現するために、次のコードを使用しています。
<xsl:for-each-group select="node()"group-starting-with="xh:h2">
<category>
<xsl:apply-templates select="xh:h2"/>
<xsl:for-each-group select="current-group()"
group-starting-with="xh:h3">
<container>
<xsl:apply-templates select="current-group()[node()]"/>
</container>
</xsl:for-each-group>
</category>
</xsl:for-each-group>
ただし、これから得られる出力は次のとおりです。
<category>
<h2 />
<container>
<h3 />
<table />
<table />
<h3 />
<table />
<table />
<h3 />
<table />
<h3 />
<h3 />
<table />
<table />
</container>
</category>
<category>
<h2 />
<container>
<h3 />
...
最初の for ループ関数は期待どおりに機能していますが、2 番目の for ループ関数は機能していないようです。>を使用して、2 番目の for ループで ><xsl:copy-of
の最初の要素を出力すると、その要素がグループ内にあってはならない > 要素が表示されます。<current-group
<h2
誰かが私が間違っている場所を指摘したり、より良い解決策を提供したりできれば、それは大歓迎です.