|
Subject: [xsl] Duplicate Nodes in XSL and transform them From: "Punnoose, Roshan" <punnooser@xxxxxxxxxxxxxxx> Date: Tue, 30 Jan 2007 12:41:00 -0500 |
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 < $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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] Storing XML doc refs in v, David Carlisle | Thread | Re: [xsl] Duplicate Nodes in XSL an, David Carlisle |
| Re: [xsl] Wrap changing element seq, David Carlisle | Date | Re: [xsl] Duplicate Nodes in XSL an, David Carlisle |
| Month |