I have a xml like this, (<p>/text() is varying)
<doc>
<p> solid 1; thick 2; solid 2;</p>
<p> double 2; thick 2; dotted 1;</p>
<p> dotted 1; double 2; dotted 2;</p>
<p> solid 2; thick 2; dotted 2;</p>
</doc>
My requirment is analize <p> node text and replace following strings,
solid 1; to solid 2;
solid 2; to solid 4;
dotted 1; to dotted 2;
dotted 2; to dotted 4;
SO, the expected output should look like this,
<doc>
<p> solid 2; thick 2; solid 4;</p>
<p> double 2; thick 2; dotted 2;</p>
<p> dotted 2; double 2; dotted 4;</p>
<p> solid 4; thick 2; dotted 4;</p>
</doc>
I wrote following xslt to do this task,
<xsl:template name='replace-text'>
<xsl:param name='text'/>
<xsl:param name='replace'/>
<xsl:param name='by'/>
<xsl:choose>
<xsl:when test='contains($text, $replace)'>
<xsl:value-of select='substring-before($text, $replace)'/>
<xsl:value-of select='$by' disable-output-escaping='yes'/>
<xsl:call-template name='replace-text'>
<xsl:with-param name='text' select='substring-after($text, $replace)'/>
<xsl:with-param name='replace' select='$replace'/>
<xsl:with-param name='by' select='$by'/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$text'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="p/text()">
<xsl:call-template name="replace-text">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="replace" select="'solid 1'"/>
<xsl:with-param name="by" select="'solid 2'"/>
</xsl:call-template>
</xsl:template>
But here I only can pass one parameter at a time. I,m struggling to implement a method in factional programming to this scenario, Can anyone suggest me a method to do this task?
replace()function calls. This solution allows an external mapping for the replacement to be specified. Enjoy!