新しい要素に含める必要があるシーケンシャル ノードのセットがあります。例:
<root>
<c>cccc</c>
<a gr="g1">aaaa</a> <b gr="g1">1111</b>
<a gr="g2">bbbb</a> <b gr="g2">2222</b>
</root>
これはタグで囲む必要がありfold
、(XSLT の後) は次のようになります。
<root>
<c>cccc</c>
<fold><a gr="g1">aaaa</a> <b gr="g1">1111</b></fold>
<fold><a gr="g2">bbbb</a> <b gr="g2">2222</b></fold>
</root>
だから、私は「グループ化のためのラベル」(@gr
)を持っていますが、正しい折りタグを作成する方法を想像していません.
この質問またはこの他の質問の手がかりを使用しようとしています...しかし、「グループ化のラベル」があるため、私のソリューションではkey()
関数を使用する必要がないことを理解しています。
私の非一般的な解決策は次のとおりです。
<xsl:template match="/">
<root>
<xsl:copy-of select="root/c"/>
<fold><xsl:for-each select="//*[@gr='g1']">
<xsl:copy-of select="."/>
</xsl:for-each></fold>
<fold><xsl:for-each select="//*[@gr='g2']">
<xsl:copy-of select="."/>
</xsl:for-each></fold>
</root>
</xsl:template>
一般的な解決策 (!) が必要です。すべての @gr でループし、@gr を持たないすべてのコンテキスト (ID) に対処します...おそらくID 変換を使用します。
もう 1 つの (将来の) 問題は、折り畳みの折り畳みを使用して、これを再帰的に行うことです。