[Home] [By Thread] [By Date] [Recent Entries]
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@xxxxxxxxx> wrote: Hi All, I have requirement to loop through the node N number of times, Is there any way I can accomplish in XSLT? -- Regards, Mukul Gandhi
|

Cart



