Subject: RE: [xsl] Duplicate Nodes in XSL and transform them From: "Punnoose, Roshan" <punnooser@xxxxxxxxxxxxxxx> Date: Tue, 30 Jan 2007 13:13:23 -0500 |
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: Input: <anything> <innerAnyThing> <anyValue>replaceMe</ anyValue > </ innerAnyThing > <innerAnyThing> <another> <anyValue>replaceMe</ anyValue > </another> </ innerAnyThing > <innerAnyThing> <anyValue>replaceMe</ anyValue > </ innerAnyThing > </anything> Assuming input is 3 iterations the output of last one would be: <anything> <innerAnyThing> <anyValue>replaced1</ anyValue > </ innerAnyThing > <innerAnyThing> <another> <anyValue> replaced1</ anyValue > </another> </ innerAnyThing > <innerAnyThing> <anyValue> replaced1</ anyValue > </ innerAnyThing > </anything> <anything> <innerAnyThing> <anyValue>replaced2</ anyValue > </ innerAnyThing > <innerAnyThing> <another> <anyValue> replaced2</ anyValue > </another> </ innerAnyThing > <innerAnyThing> <anyValue> replaced2</ anyValue > </ innerAnyThing > </anything> <anything> <innerAnyThing> <anyValue>replaced3</ anyValue > </ innerAnyThing > <innerAnyThing> <another> <anyValue> replaced3</ anyValue > </another> </ innerAnyThing > <innerAnyThing> <anyValue> replaced3</ anyValue > </ innerAnyThing > </anything> 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.) Roshan Punnoose Phone: 301-497-6039 Roshan Punnoose Phone: 301-497-6039 -----Original Message----- From: Michael Kay [mailto:mike@xxxxxxxxxxxx] Sent: Tuesday, January 30, 2007 12:57 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] Duplicate Nodes in XSL and transform them > -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) Generally, it's reasonably easy to generate numbers that are computed by reference to the position of a node in the source tree. In some special cases you can also use position() to generate a number that reflects the position in the result tree. But in the general case, this kind of problem is best tackled as a two-pass transformation, in which you generate the numbers in the second pass. For example, rather than inserting a sequential number, insert <n/>, and then in the second pass do a "modified copy" transformation with <xsl:template match="n"> <xsl:number level="any"/> </xsl:template> (You can do a two-pass transform with two stylesheets, or within a single stylesheet, whichever is most convenient. Using two stylesheets is a bit harder to set up but gives you more reusable code.) Michael Kay http://www.saxonica.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Duplicate Nodes in XSL an, Michael Kay | Thread | Re: [xsl] Duplicate Nodes in XSL an, Abel Braaksma |
RE: [xsl] Duplicate Nodes in XSL an, Michael Kay | Date | Re: [xsl] Duplicate Nodes in XSL an, Abel Braaksma |
Month |