I have XML in the following format which I want to reformat:
<blocks>
<!-- === apples === -->
<block name="block1">
...
</block>
<!-- === bananas === -->
<block name="block2">
...
</block>
<!-- === oranges === -->
<block name="block3">
...
</block>
</blocks>
My problem is I can't figure out how to select the comments above each block tag. I have the following XSL:
<xsl:template match="//blocks">
<xsl:apply-templates select="block" />
</xsl:template>
<xsl:template match="block">
<xsl:apply-templates select="../comment()[following-sibling::block[@name = ./@name]]" />
<xsl:value-of select="./@name" />
</xsl:template>
<xsl:template match="comment()[following-sibling::block]">
<xsl:value-of select="."></xsl:value-of>
</xsl:template>
The output that I am trying for is:
=== apples ===
block1
=== bananas ===
block2
=== oranges ===
block3
But the best I can get is:
=== apples ===
=== bananas ===
=== oranges ===
block1
=== apples ===
=== bananas ===
=== oranges ===
block2
=== apples ===
=== bananas ===
=== oranges ===
block3
I am using PHP if that makes any difference.