【发布时间】:2010-06-07 16:10:11
【问题描述】:
我正在尝试对一批 XML 文档应用 XSLT 转换。转换的要点是重新排序几个元素。我希望保留 直接 在元素之前的所有 cmets:
<!-- not this comment -->
<element />
<!-- this comment -->
<!-- and this one -->
<element />
我最接近的解决方案是使用以下表达式:
<xsl:template match="element">
<xsl:copy-of select="preceding-sibling::comment()"/>
</xsl:template>
它抓取了太多的 cmets:
<!-- not this comment -->
<!-- this comment -->
<!-- and this one -->
我理解为什么前面提到的 XPath 不能正常工作,但我对如何继续没有任何好的想法。我正在寻找的是选择所有前面的 cmets,其后续兄弟是另一个注释或正在处理的当前元素:
preceding-sibling::comment()[following-sibling::reference_to_current_element() or following-sibling::comment()]
【问题讨论】: