0

翻訳しようとしている 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

誰かが私が間違っている場所を指摘したり、より良い解決策を提供したりできれば、それは大歓迎です.

4

2 に答える 2

0

私はあなたが変わりたいと思う

<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">

<xsl:for-each-group select="*" group-starting-with="xh:h2">
    <category>
        <xsl:apply-templates select="."/>
        <xsl:for-each-group select="current-group() except ." 
                    group-starting-with="xh:h3">

そうすれば、内側は要素と要素をfor-each-group処理しますが、外側のグループを開始する要素は処理しません。h3tableh2

さらに支援が必要な場合は、名前空間が存在する小さいが完全なサンプルを投稿して、望ましくない出力で問題を再現できるようにすることを検討してください。

于 2013-07-04T10:41:08.460 に答える