Subject: Re: [xsl] for i = 1 to 10, or while (is there an equivalent?) From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx> Date: Tue, 9 Nov 2004 22:48:11 -0800 (PST) |
Hi Steven, Please try this XSL - <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" /> <xsl:template match="/"> <xsl:call-template name="escapeString"> <xsl:with-param name="str" select="elem" /> <xsl:with-param name="escapeChars" select="'\ "'" /> <xsl:with-param name="newstr" select="''" /> </xsl:call-template> </xsl:template> <xsl:template name="escapeString"> <xsl:param name="str" /> <xsl:param name="escapeChars" /> <xsl:param name="newstr" /> <xsl:choose> <xsl:when test="substring($str, 1, 1) != ''"> <xsl:choose> <xsl:when test="contains($escapeChars, substring($str,1,1))"> <xsl:call-template name="escapeString"> <xsl:with-param name="str" select="substring($str, 2)" /> <xsl:with-param name="escapeChars" select="$escapeChars" /> <xsl:with-param name="newstr" select="concat($newstr, '\', substring($str, 1, 1))" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="escapeString"> <xsl:with-param name="str" select="substring($str, 2)" /> <xsl:with-param name="escapeChars" select="$escapeChars" /> <xsl:with-param name="newstr" select="concat($newstr, substring($str, 1, 1))" /> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:value-of select="$newstr" /> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> When it is applied to the XML - <?xml version="1.0" encoding="UTF-8"?> <elem>foo\bar"xxx</elem> it produces o/p - foo\\bar\"xxx Regards, Mukul --- Steven Reddie <smr@xxxxxxxxxxxxxx> wrote: > Hi, > > I'm probably going about this the wrong way, but I > have a C string in a > variable that I want to escape the backslashes and > double-quotes prior to > output. ie. foo\bar"xxx -> foo\\bar\"xxx > I figured I could use the XPath contain and > substring functions to do what I > want, but I can't find a way to iterate until there > are no more characters > of interest. Can this be done in XSL/XPath? > > Regards, > > Steven __________________________________ Do you Yahoo!? Check out the new Yahoo! Front Page. www.yahoo.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] for i = 1 to 10, or while, Geert Josten | Thread | Re: [xsl] for i = 1 to 10, or while, Elliotte Harold |
RE: [xsl] for i = 1 to 10, or while, Arun Sinha | Date | RE: [xsl] Create a bit mask ?, Jarno.Elovirta |
Month |