xsl-list
[Top] [All Lists]

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

2007-01-30 10:57:00
-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/


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