You can also use only one expression in XSLT / XPath 2.0:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="text()"/>
<xsl:template match="p[position()=(1,3,4)]">
<xsl:copy-of select="following-sibling::*
[not(self::h2|self::h1)]
[not(. >>
current()
/following-sibling::*
[self::h2|self::h1][1])]"/>
</xsl:template>
</xsl:stylesheet>
With this input:
<html>
<p>1</p>
<p>2</p>
<h2>Header</h2>
<p>3</p>
<h1>Header</h1>
<p>4</p>
<p>5</p>
</html>
Output:
<p>2</p><p>5</p>
user357812
source
share