cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Burnett-Hall <olly...@blueyonder.co.uk>
Subject Re: ESQL query with ' and " special chars
Date Mon, 19 May 2003 19:49:09 GMT
On Mon, 2003-05-19 at 16:00, Tomasz Nowak wrote:
<snip>
> I get XSP:
> 
> ---XSP----------------------------------------------------
> [...]
> <esql:execute-query>
>   <esql:query>
>     INSERT
>       INTO articles (id, title, body)
>       VALUES (
>         123,
>         'This is a title',
>         '&lt;body&gt;Someone's "something"&lt;/body&gt;'
>       )
>   </esql:query>
> </esql:execute-query>
> [...]
> ----------------------------------------------------------
> 
> Which doesn't go throught database correcty because of a ' sign.

There's probably an easy and elegant solution to this, but I don't know
it.  I can give you a brute force instead.

If your <body> element just contains text, the following templates will
transform it and escape any apostrophes present, replacing them with
&apos; character entities:

<xsl:template match="body">
	<xsl:text>&lt;body&gt;</xsl:text>
	<xsl:call-template name="escape-apos">
		<xsl:with-param name="text" select="."/>
	</xsl:call-template>
	<xsl:text>&lt;/body&gt;</xsl:text>
</xsl:template>

<xsl:template name="escape-apos">
<xsl:param name="text"/>
<xsl:variable name="apos">'</xsl:variable>
	<xsl:choose>
		<xsl:when test="contains($text, $apos)">
			<xsl:value-of select="substring-before(
				$text, $apos)"/>
			<xsl:text disable-output-escaping="yes">&amp;apos;</xsl:text>
			<xsl:call-template name="escape-apos">
				<xsl:with-param name="text" 					select="substring-after(
					$text, $apos)"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$text"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

Double quotes shouldn't be a problem, so you can just ignore them.

HTH,

- olly

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Mime
View raw message