0

Hello ,
Please help me, i am facing problem to divide the xml in two parts.

The xml is
<aa>
<x>1</x>
<x>2</x>
<x>3</x>
<x>4</x>
<x>5</x>
<x>6</x>
<x>7</x>
<x>8</x>
<x>9</x>
<x>10</x>
</aa>

the x element contain some attriubte and child elements.

and i want to divide the xml into two parts as follows:

<bb>
<x>1</x>
<x>2</x>
<x>3</x>
<x>4</x>
<x>5</x>
</bb>
<cc>
<x>6</x>
<x>7</x>
<x>8</x>
<x>9</x>
<x>10</x>
</cc>

means first 5 into bb tag and others in cc tag. could you please help me

thanks in advance

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by varun0703
0
<bb>
  <xsl:apply-templates select="x[position() &lt;= 5]" />
</bb>
<cc>
  <xsl:apply-templates select="x[position() &gt; 5]" />
</cc>
0

Use following code:-

<bb>
<xsl:for-each select="//x">
<xsl:if test="position() &lt;6">

<xsl:copy-of select="."/>

</xsl:if>
</xsl:for-each>
</bb>
<cc>
<xsl:for-each select="//x">
<xsl:if test="position() &gt;5">

<xsl:copy-of select="."/>

</xsl:if>
</xsl:for-each>
</cc>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.