[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Looping a node in XSLT

Subject: Re: Looping a node in XSLT
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 7 Mar 2007 18:54:44 +0530
Re:  Looping a node in XSLT
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 &lt; $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?


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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.