1
私はxsltでかなり新しく、本当に面倒なグループマージのケースを見つけました。私は、次のXML構造:特定の子ノードに基づいてxmlノードをグループ化してマージする
<root>
<section name="A">
<table name="B">
<row1/>
</table>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
<section name="C"></section>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
</section>
</root>
を、私はそれがCの名前の子セクションを含むセクションに直面するまでのコードだけROW1をマージしなければならないような方法でそれを変換する必要があります。
<xsl:template match="section[@name='A' and following-sibling::section[@name='A'] ]//table[1]" >
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="ancestor::section[@name='A']/following-sibling::section[@name='A']//table[1]/row1" />
</xsl:copy>
</xsl:template>
<xsl:template match="section[ @name='A' and preceding-sibling::section[@name='A'] ]//table[1]" />
私を助けてください。私は今のところちょうどすべてのセクション内のすべての行をマージしている何
<root>
<section name="A">
<table name="B">
<row1/>
<row1/>
</table>
</section>
<section name="A">
<table name="B">
<row1/>
</table>
<section name="C"></section>
</section>
<section name="A">
<table name="B">
<row1/>
<row1/>
</table>
</section>
</root>
。まあ
これは宝石のように機能しますが、for-eachループに関する小さな質問がありました。ループはノードを処理する順序を保持しているのか、それとも現在のグループ(current-group)それは何ですか? – V15720002000
あなたは 'for-each-group'について質問していますか? 'select =" * 'によって選択された集団集団を集団順に処理し、グループの後に集団を形成します。詳細については、https://www.w3.org/TR/xslt20/#xsl-for-each-groupを参照してください。 –