Find and replace entity in xslt

dwighthot

New Member
i need to find and replace an entity in xslt. i need to do this without using template match.suppose my xml like this,\[code\]<root> <p>Master&apos;s</p> <p><blockFixed type="quotation"><p>let&apos;s</p></blockFixed></p> <p>student&apos;s<featureFixed id=1/></p> <p><blockFixed type="quotation"><p>nurse&apos;s</p></blockFixed></p> <p>Master&apos;s</p></root>\[/code\]i need to change \[code\]&apos;\[/code\] into \[code\]&rsquo;\[/code\] so output should be like this,\[code\]<root> <p>Master<apos>&rsquo;</apos>s</p> <p><blockFixed type="quotation"><p>let<apos>&rsquo;</apos>s</p></blockFixed></p> <p>student<apos>&rsquo;</apos>s<featureFixed id=1/><\p> <p><blockFixed type="quotation"><p>nurse<apos>&rsquo;</apos>s</p></blockFixed></p> <p>Master&apos;s</p></root>\[/code\]i used the replace method by using template match \[code\]p\[/code\] but after that i can not able to do any operation on other tags like \[code\]blockfixed\[/code\] etc,. so pls suggest simple xslt to do this.i used the following xslt,\[code\] <xsl:template match="p"> <xsl:copy> <xsl:apply-templates select="current()/node()" mode="replace"/> </xsl:copy> </xsl:template> <xsl:template match="text()" mode="replace"><xsl:call-template name="replace-string"> <xsl:with-param name="text" select="."/> <xsl:with-param name="from">&apos;</xsl:with-param> <xsl:with-param name="to" select="'&rsquo;'"/></xsl:call-template></xsl:template><xsl:template name="replace-string"><xsl:param name="text"/><xsl:param name="from"/><xsl:param name="to"/><xsl:choose> <xsl:when test="contains($text, $from)"> <xsl:variable name="before" select="substring-before($text, $from)"/> <xsl:variable name="after" select="substring-after($text, $from)"/> <xsl:variable name="prefix" select="concat($before, $to)"/> <xsl:copy-of select="$before"/> <Apos> <xsl:copy-of select="$to"/> </Apos> <xsl:call-template name="replace-string"> <xsl:with-param name="text" select="$after"/> <xsl:with-param name="from" select="$from"/> <xsl:with-param name="to" select="$to"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:copy-of select="$text"/> </xsl:otherwise> </xsl:choose> </xsl:template>\[/code\]thanks in advance.
 
Back
Top