Here is a XSLT 1.0 solution, tested with Xalan-J 2.7.0:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:param name="n" />
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="prod">
<xsl:param name="x" select="0" />
<xsl:if test="$x < $n">
<xsl:copy-of select="." />
<xsl:apply-templates select=".">
<xsl:with-param name="x" select="$x + 1" />
</xsl:apply-templates>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
When I invoke Xalan-J as following:
java org.apache.xalan.xslt.Process -in test.xml -xsl test.xsl -PARA
M n 4
I get output:
<?xml version="1.0" encoding="UTF-8"?>
<order>
<orderid>10</orderid>
<prod>
<productid>100</productid>
<productqty>200</productqty>
</prod>
<prod>
<productid>100</productid>
<productqty>200</productqty>
</prod>
<prod>
<productid>100</productid>
<productqty>200</productqty>
</prod>
<prod>
<productid>100</productid>
<productqty>200</productqty>
</prod>
</order>
Hope this helps.
On 3/7/07, Senthilkumaravelan Krishnanatham <senthil(_at_)apple(_dot_)com>
wrote:
Hi All,
I have requirement to loop through the node N number of times,
Is there any way I can accomplish in XSLT?
for example
<order>
<orderid>10</orderid>
<prod>
<productid>100</productid >
<productqty>200< productqty>
</prod>
</order>
Desired out put
<order>
<orderid>10</orderid>
<prod>
<productid>100</productid >
<productqty>200< productqty>
</prod>
<prod>
<productid>100</productid >
<productqty>200< productqty>
</prod>
<prod>
<productid>100</productid >
<productqty>200< productqty>
</prod>
... N times
</order>
Thanks,
Senthil
--
Regards,
Mukul Gandhi
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--