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

Recommended Answers

All 2 Replies

<bb>
  <xsl:apply-templates select="x[position() &lt;= 5]" />
</bb>
<cc>
  <xsl:apply-templates select="x[position() &gt; 5]" />
</cc>

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>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.