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

Re: Duplicate Nodes in XSL and transform them

Subject: Re: Duplicate Nodes in XSL and transform them
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 30 Jan 2007 20:02:35 +0100
Re:  Duplicate Nodes in XSL and transform them
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

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.