xsl-list
[Top] [All Lists]

Re: [xsl] Duplicate Nodes in XSL and transform them

2007-01-30 12:04:13
Punnoose, Roshan wrote:
I see what you mean, but I guess the case I gave was a little too
simple. What I really want to do is take any nodeset and copy it n times
and replace a string in each copy. Like this:

The case you gave was a little too complex (see below)

That's why I thought that replacing the string using the XPath string
replace would be the best idea, but I didn't know how to process a node
set as a string and then convert it back to a node set. (Unless there is
a better way to do it.)

I think you are making this very difficult and it don't need be. If I take the following rules based on your past mails and your above example (thanks!):

1) input xml can be anything, whole xml must be copied
2) somewhere in the input xml there is a string that must be replaced, but you don't know the path to that string 3) it must be replace with the nr of the current copy plus the string 'replace'

This will suffice for those rules (and provide your example output from your example input, after you make it legal XML) with XSLT 2:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">
   <xsl:output indent="yes" />
   <xsl:param name="nr-of-copies" select="5" />
<xsl:template match="/">
       <xsl:variable name="anchor" select="." />
       <xsl:for-each select="1 to $nr-of-copies">
           <xsl:apply-templates select="$anchor" >
               <xsl:with-param name="iteration" tunnel="yes" select="."/>
           </xsl:apply-templates>
       </xsl:for-each>
   </xsl:template>
<xsl:template match="node()">
       <xsl:copy><xsl:apply-templates /></xsl:copy>
   </xsl:template>
<xsl:template match="text()[matches(., 'replaceMe')]">
       <xsl:param name="iteration"  tunnel="yes"/>
       <xsl:text>replace</xsl:text>
       <xsl:value-of select="$iteration" />
   </xsl:template>
</xsl:stylesheet>


Cheers,
-- Abel Braaksma
  http://www.nuntia.nl



--~------------------------------------------------------------------
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>
--~--