|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] search and replace multiple characters fails
I have been working with XSLT 6 weeks. I am having trouble with
searching and replacing for multiple characters (one character is no
problem).
<xsl:when test="contains($string, '•')">
<xsl:value-of select="substring-before($string, '•')" />
<xsl:value-of select="$newchar2"/>
<xsl:call-template name="SANDR">
<xsl:with-param name="string"
select="substring-after($string, '•')"/>
<xsl:with-param name="newchar2" select="$newchar2"/>
</xsl:call-template>
</xsl:when><xsl:when test="contains($string, '▪')">
<xsl:value-of select="substring-before($string, '▪')"/>
<xsl:value-of select="$newchar3"/>
<xsl:call-template name="SANDR">
<xsl:with-param name="string"
select="substring-after($string, '▪')"/>
<xsl:with-param name="newchar3" select="$newchar3"/>
</xsl:call-template>
</xsl:when><xsl:when test="contains($string, '@')">
<xsl:value-of select="substring-before($string, '@')"/>
<xsl:value-of select="$newchar4"/>
<xsl:call-template name="SANDR">
<xsl:with-param name="string"
select="substring-after($string, '@')"/>
<xsl:with-param name="newchar4" select="$newchar4"/>
</xsl:call-template>
</xsl:when><xsl:when test="contains($string, '–')">
<xsl:value-of select="substring-before($string, '–')"/>
<xsl:value-of select="$newchar5"/>
<xsl:call-template name="SANDR">
<xsl:with-param name="string"
select="substring-after($string, '–')"/>
<xsl:with-param name="newchar5" select="$newchar5"/>
</xsl:call-template>
</xsl:when><xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise> </xsl:choose> </xsl:template> Obviously, this template has at least one problem: If a TextString has more than one of these characters, only the 1st one found gets replaced. (When one of the conditions is met for a given context node, the processor stops looking at the other ones, thus making it unable to find & replace more than one character in this manner). I came up with a solution that SHOULD work but doesn't. Basically, rather than having one template with 5 conditions, i chose to have 5 different templates each with one condition; but i have some rather unexpected results.
<xsl:call-template name="CHARFIX2"> <xsl:with-param name="string" select="."/> <xsl:with-param name="newchar2" select="'<\#165>'"/> </xsl:call-template> &etc, for CHARFIX3, CHARFIX4, CHARFIX5 </xsl:call-template> </xsl:template>
&etc, for CHARFIX2, CHARFIX3, and CHARFIX4 until 5 which goes:
With this S and R routine, I get only the FIRST occurrence of any character in the list. So where before i got: <\#165> Text. Text Text. <\#165> Text Text. <\#165> Text now i get: <\#165> Text. Text Text. ? Text Text. ? Text (where <\#165> is a successful replacement and ? is not) I don't understand why this is happening. Can anyone see what is wrong here? ANd if there is a problem inherent for search and replace for multiple characters--how do other folks deal with it?
Greg Martel
Greg Martel Coordinator of Enchiladas XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








