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

Duplicate Nodes in XSL and transform them

Subject: Duplicate Nodes in XSL and transform them
From: "Punnoose, Roshan" <punnooser@xxxxxxxxxxxxxxx>
Date: Tue, 30 Jan 2007 12:41:00 -0500
 Duplicate Nodes in XSL and transform them
I might be asking for too much from XSL, but this is what I want to do:

-A template that takes any node and copies it
-Each copy has to replace a string "replaceMe" with the string
"replaced" + i. ( 'i' being the iteration of the copy)

So something like this:

Before:

<element>
  <innerElement>
    <value>replaceMe</value>
  </innerElement>
</element>

After , 3 copies of the innerElement:

<element>
  <innerElement>
    <value>replaced1</value>
  </innerElement>
<innerElement>
    <value>replaced2</value>
  </innerElement>
<innerElement>
    <value>replaced3</value>
  </innerElement>
</element>


So I was thinking of writing a template that would do look like this:

<!-print all iterations --:
<xsl:template name="print">
                        <xsl:param name="node"/>
                        <xsl:param name="times"/>
                        <xsl:call-template name="loop">
                                    <xsl:with-param name="a"
select="1"/>
                                    <xsl:with-param name="times"
select="$times"/>
                        </xsl:call-template>
            </xsl:template>
            <xsl:template name="loop">
                        <xsl:param name="a"/>
                        <xsl:param name="times"/>
                        <xsl:call-template name="printNode">
                                    <xsl:with-param name="a"
select="$a"/>
                        </xsl:call-template>
                        <!-- Test condition and call template if less
than number -->
                        <xsl:if test="$a &lt; $times">
                                    <xsl:call-template name="loop">
                                                <xsl:with-param name="a"
select="$a + 1"/>
                                                <xsl:with-param
name="times" select="$times"/>
                                    </xsl:call-template>
                        </xsl:if>
            </xsl:template>
            <xsl:template name="printNode">
                        <xsl:param name="a"/>
                        <xsl:copy>
                                    //Copy the current node and replace
string("replaceMe") with string("replaced" + a)
                        </xsl:copy>
            </xsl:template>

I thought of doing a string replace and then serializing the output out
as xml, but I can't seem to figure this out.

Any ideas?


Roshan Punnoose
Phone: 301-497-6039


Roshan Punnoose
Phone: 301-497-6039

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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-2013 All Rights Reserved.