我正在尝试将XSLT转换应用于一批XML文档。转换的要点是重新排列几个元素。我希望直接之前的元素保留任何意见:xslt&xpath:直接匹配前注释
<!-- not this comment -->
<element />
<!-- this comment -->
<!-- and this one -->
<element />
我来解决最接近的是使用表达式:
<xsl:template match="element">
<xsl:copy-of select="preceding-sibling::comment()"/>
</xsl:template>
其抓住太多的评论:
<!-- not this comment -->
<!-- this comment -->
<!-- and this one -->
我明白为什么上述XPath无法正常工作,但我对如何继续操作没有任何好的想法。我正在寻找的是什么来选择前面的所有意见,其下面的同辈或者是处理其他评论或当前元素:
preceding-sibling::comment()[following-sibling::reference_to_current_element() or following-sibling::comment()]
谢谢,您的解决方案完美的作品!我必须对generate-id()和key()进行一些阅读。 – 2010-06-07 16:36:34
@Joshua Johnson:关键:我已经写了一些解释他们如何处理JavaScript示例的东西,请看看你是否想要:http://stackoverflow.com/questions/948218/xslt-3-level- grouping-on-attributes/955527#955527(只读了答案的下半部分)。 – Tomalak 2010-06-07 16:49:40