一連の同じレベルのノードである入力ドキュメントが与えられた場合、2 つのフラグ (それ自体がノード) の間にあるノードを見つけたいと考えています。フラグは複数回使用でき、最終的な結果には、同じフラグ間のすべてのコンテンツがグループ化されている必要があります。私はこれに打ちのめしています。
次の入力ドキュメントがあるとします。
<root>
<p class="text">Hello world 1.</p>
<p class="text">Hello world 2.</p>
<p class="text">Hello world 3.</p>
<p class="excerptstartone">Dummy text</p> <!-- this flag identifies the start of the nodes I want to select -->
<p class="text">Hello world 4.</p>
<p class="text">Hello world 5.</p>
<p class="text">Hello world 6.</p>
<p class="excerptendone">Dummy text</p> <!-- this flag identifies the end of the nodes I want to select -->
<p class="text">Hello world 7.</p>
<p class="excerptstarttwo">Dummy text</p> <!-- this flag identifies the start of the nodes I want to select -->
<p class="text">Hello world 8.</p>
<p class="excerptendtwo">Dummy text</p> <!-- this flag identifies the end of the nodes I want to select -->
<p class="text">Hello world 9.</p>
<p class="excerptstartone">Dummy text for starting a new excerpt</p> <!-- this flag identifies the start of the nodes I want to select -->
<p class="text">Hello world 10.</p>
<p class="text">Hello world 11.</p>
<p class="excerptendone">Dummy text</p> <!-- this flag identifies the end of the nodes I want to select -->
<p class="text">Hello world 12.</p>
<p class="text">Hello world 13.</p>
<p class="text">Hello world 14.</p>
<p class="text">Hello world 15.</p>
<p class="text">Hello world 16.</p>
<p class="text">Hello world 17.</p>
</root>
私はこの出力が欲しい:
<root>
<p class="excerptstartone">Dummy text</p>
<p class="text">Hello world 4.</p>
<p class="text">Hello world 5.</p>
<p class="text">Hello world 6.</p>
<p class="text">Hello world 10.</p>
<p class="text">Hello world 11.</p>
<p class="excerptendone">Dummy text</p>
<p class="excerptstarttwo">Dummy text</p>
<p class="text">Hello world 8.</p>
<p class="excerptendtwo">Dummy text</p>
</root>
注: フラグは常に "excerptstart" と "excerptend" で始まり、フラグのサフィックスは常に一致します (つまり、ビジネス ルールにより、"excerptstartone" がある場合は常に "excerptendone" が存在することが保証されます)。
これは私がこれまでに持っているものです。excerptstart サフィックス (つまり、「1」、「2」) をハードコーディングしている限り、必要なコレクションを見つけることができます。接尾辞をハードコードする必要がないように、一般化しようとすることに固執しています(結果ツリーに開始/終了段落の「フラグ」を保持することは気にしないと言うべきです;私はそれらをハードコードしましたここでは、結果ツリーを評価する際の便宜のために):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="root">
<root>
<p class="excerptstartone">Dummy text</p>
<xsl:for-each select="p[@class='excerptstartone']">
<xsl:sequence select="following-sibling::node() intersect following-sibling::p[@class='excerptendone'][1]/preceding-sibling::node()"/>
</xsl:for-each>
<p class="excerptendone">Dummy text</p>
<p class="excerptstarttwo">Dummy text</p>
<xsl:for-each select="p[@class='excerptstarttwo']">
<xsl:sequence select="following-sibling::node() intersect following-sibling::p[@class='excerptendtwo'][1]/preceding-sibling::node()"/>
</xsl:for-each>
<p class="excerptendtwo">Dummy text</p>
</root>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>