I am trying to apply an XSLT transform to XML batch documentation. The main point of the transformation is the reordering of several elements. I want to keep any comments that immediately precede the element:
<element />
<element />
The closest I came to a solution was to use the expression:
<xsl:template match="element">
<xsl:copy-of select="preceding-sibling::comment()"/>
</xsl:template>
which captures too many comments:
I understand why the aforementioned XPath does not work correctly, but I have no good ideas on how to proceed. What I'm looking for is something to select all previous comments, the next of which is either another comment or the current item being processed:
preceding-sibling::comment()[following-sibling::reference_to_current_element() or following-sibling::comment()]