[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Punnoose, Roshan wrote:
The case you gave was a little too complex (see below)
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>
Re: [xsl] Duplicate Nodes in XSL and transform them
Subject: Re: [xsl] Duplicate Nodes in XSL and transform them From: Abel Braaksma <abel.online@xxxxxxxxx> Date: Tue, 30 Jan 2007 20:02:35 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Duplicate Nodes in XSL an, Punnoose, Roshan | Thread | Re: [xsl] Duplicate Nodes in XSL an, David Carlisle |
RE: [xsl] Duplicate Nodes in XSL an, Punnoose, Roshan | Date | Re: [xsl] Duplicate Nodes in XSL an, David Carlisle |
Month |