cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luca Morandini <luca.morandi...@tin.it>
Subject Re: escaping characters
Date Thu, 24 Jul 2003 08:06:12 GMT
Mustafa Yalniz wrote:

> 
> I get the info lets say lastname (Irish name could cause problem) from
> 
>   <lastname><sunshine:getxml context="request" 
> path="/parameter/lastname"/></lastname>
> 
> and apply sunshine transformer.
> 
> later I insert it into the database as below.
> 
>         insert into user_tb
>            set name = '<xsl:value-of select="name"/>',
>               ...
>                lastname = '<xsl:value-of select="lastname"/>'
> 
> And the lastname has syntax error in case last name is e.g. O'Reilly.
> 
> My question is is there a way in cocoon to process and replace the 
> characters with escape ones.
> 

Since you're using XSL to prepare the SQL string, it makes sense to call 
an XSL template escaping those single quotes: such a template follows:

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

Warning: this is not a fast approach ! A better one may be calling java 
methods within XSL (see XSL Extensions in Xalan).

Regards,

------------------------------------------
                Luca Morandini
                GIS Consultant
               lmorandini@ieee.org
http://space.virgilio.it/kumora/index.html
------------------------------------------



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


Mime
View raw message