I have a XML s开发者_JAVA百科imilar to this
<a>
<b>text1</b>
<b>text2</b>
<b>text3</b>
.....
....
</a>
This is the output required
<div>text1 text2</div>
<div>text3 text4</div>
Adding a wrapping div for all the text or adding individual div's for each text is easy with the xsl foreach. How can I accomplish the above requirement where div needs to added for 2 texts at a time?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="a/b[position() mod 2 = 1]"/>
</xsl:template>
<xsl:template match="b">
<div>
<xsl:value-of select="concat(., ' ', following-sibling::b)"/>
</div>
</xsl:template>
</xsl:stylesheet>
精彩评论