xsl-list
[Top] [All Lists]

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

2007-01-30 12:55:13
That worked! Thanks!

Roshan Punnoose
Phone: 301-497-6039

-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk] 
Sent: Tuesday, January 30, 2007 2:30 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Duplicate Nodes in XSL and transform them



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.)

you don't want to serialise, replace, then re-parse (which would take
extension elements) you just need to apply the replacement separately to
each text node. 

Abel has shown an xslt2 solution, if you are using xslt1 then
a small modification of the code I sent earlier:


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:template match="*">
  <xsl:param name="n"/>
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates>
      <xsl:with-param name="n" select="$n"/>
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<xsl:template match="text()[.='replaceMe']">
  <xsl:param name="n"/>
  <xsl:text>replaced</xsl:text>
  <xsl:value-of select="$n"/>
</xsl:template>

<xsl:template match="anything">
  <xsl:copy>
    <xsl:variable name="x" select="."/>
    <xsl:for-each select="(//node())[position()&lt;4]">
    <xsl:apply-templates select="$x/node()">
      <xsl:with-param name="n" select="position()"/>
    </xsl:apply-templates>
    </xsl:for-each>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>



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


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

<Prev in Thread] Current Thread [Next in Thread>