Subject: [xsl] Multiple search and replace From: "Pankaj Chaturvedi" <pankaj.chaturvedi@xxxxxxxxx> Date: Wed, 2 Apr 2008 11:36:02 +0530 |
Hi all, I am trying to define multiple search and replace in style sheet. Basically trying to convert [#x02010] (and other Unicode values) to their corresponding values ‐ . Below is what I am trying to do: <xsl:template match="text()"> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="."/> <xsl:with-param name="find" select="'[#'"/> <xsl:with-param name="replace" select="'&#'"/> </xsl:call-template> </xsl:template> <xsl:template name="_replace_string"> <xsl:param name="string" select="''"/> <xsl:param name="find" select="''"/> <xsl:param name="replace" select="''"/> <xsl:choose> <xsl:when test="contains($string,$find)"> <xsl:value-of select="concat(substring-before($string,$find),$replace)"/> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="substring-after($string,$find)"/> <xsl:with-param name="find" select="$find"/> <xsl:with-param name="replace" select="$replace"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string"/> </xsl:otherwise> </xsl:choose> </xsl:template> I have two questions in regard: 1. I am bound to define & as & as XMLSpy giving an error "character is grammatically unexpected". Is there other way of overcoming this issue and get & in output. 2. I also need to replace "]" to ";" for which I was trying to call the another template with in <xml:template match="text()"> as below but doesn't seems to be working. <xsl:param name="again_find" select="''"/> <xsl:param name="again_replace" select="''"/> <xsl:when test="contains($string,$again_find)"> <xsl:value-of select="concat(substring-before($string,$again_find),$again_replace)"/ > <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="substring-after($string,$again_find)"/> <xsl:with-param name="again_find" select="$again_find"/> <xsl:with-param name="again_replace" select="$again_replace"/> </xsl:call-template> </xsl:when>--> <xsl:otherwise> <xsl:value-of select="$string"/> </xsl:otherwise> </xsl:choose> Can we do multiple search and replaces in one named template or do I need to define them all separately (I need to call all of them in one template <xsl:template match="text()">). Best, Pankaj Chaturvedi ============================================================================ ================ Confidentiality Notice:" This message and any attachment(s) contained here are information that is confidential, proprietary to IDS Infotech Ltd. and its customers. Contents may be privileged or otherwise protected by law. The information is solely intended for the individual or the entity it is addressed to. If you are not the intended recipient of this message, you are not authorized to read, forward, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer."
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Counting occurences of a , Dimitre Novatchev | Thread | Re: [xsl] Multiple search and repla, Abel Braaksma |
Re: [xsl] Counting occurences of a , Dimitre Novatchev | Date | Re: [xsl] Multiple search and repla, Abel Braaksma |
Month |