Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - how to find deep nested double quotes in a string using XSLT >Thread Next - Re: how to find deep nested double quotes in a string using XSLT Re: how to find deep nested double quotes in a string using XSLTTo: NULL Date: 8/1/2005 5:46:00 PM Satya Karri wrote: > I have a string - Hello"world",test "purpose" > > I want to use XLST to turn this one into - "Hello""world"",test ""purpose""" > > I try to replace every double quote into two doublequotes for the purpose of > outputting CSV file format using XSLT. You need to write a recursive template that looks for a double quote, takes the string before it, adds two double quote characters, and calls the template on the remaining string. So if you want to transform Hello"world",test "purpose" into Hello""world"",test ""purpose"" you could do it alike this: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text" /> <xsl:param name="input" select="'Hello"world",test "purpose"'" /> <xsl:param name="defaultCharacter" select="'"'" /> <xsl:template match="/"> <xsl:call-template name="duplicateCharacter"> <xsl:with-param name="inputString" select="$input" /> </xsl:call-template> </xsl:template> <xsl:template name="duplicateCharacter"> <xsl:param name="inputString" /> <xsl:param name="characterToDuplicate" select="$defaultCharacter" /> <xsl:choose> <xsl:when test="contains($inputString, $characterToDuplicate)"> <xsl:variable name="head" select="concat(substring-before($inputString, $characterToDuplicate), $characterToDuplicate, $characterToDuplicate)" /> <xsl:variable name="tail"> <xsl:call-template name="duplicateCharacter"> <xsl:with-param name="inputString" select="substring-after($inputString, $characterToDuplicate)" /> <xsl:with-param name="characterToDuplicate" select="$characterToDuplicate" /> </xsl:call-template> </xsl:variable> <xsl:value-of select="concat($head, $tail)" /> </xsl:when> <xsl:otherwise><xsl:value-of select="$inputString" /></xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> Or look into existing solutions to replace a substring with another string, one is here: <http://www.exslt.org/str/functions/replace/index.html> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
