开发者

XSL 1.0 How to add div tags to two elements/text at a time

开发者 https://www.devze.com 2023-04-13 07:05 出处:网络
I have a XML s开发者_JAVA百科imilar to this <a> <b>text1</b> <b>text2</b>

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消