[xslt] Re: question about single quote
- From: Dan Allen <mojavelinux yahoo com>
- To: xslt gnome org, oliver feige triplex de
- Subject: [xslt] Re: question about single quote
- Date: Tue, 27 Nov 2001 09:37:55 -0800
Ah yes, your problem is clear. When creating a quoted string as an xPath expression, you cannot use ' or ' if you use single quotes. You must do something like this
select="concat('',"'",'')"
or reverse the original quotes
select='"'"'
or first create a variable such as
<xsl:variable name="tmp">'</xsl:variable>
in the case of your function, if you pass the string in as a variable, it will be internally escaped and you won't have to worry about any of this. So this all comes when you are trying hardcode a test string into your function call. The easiest way around all this is to use the tmp variable...then you can just do:
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="normalize-space(/doc)"/>
<xsl:with-param name="replace" select="$tmp"/>
<xsl:with-param name="with" select="'"'"/>
</xsl:call-template>
Dan Allen
> Hi,
>
> I have a question about the xslt functions substring-before and
> substring-after. I use this xml File:
>
> <?xml version="1.0" encoding="ISO8859-1"?>
> <?xml-stylesheet href="http://ap-lnx-ofeige.client/xsl-bin/foo.xsl"
> type="text/xsl"?> <doc>Hello 'world'</doc>
>
> I like to do a search and replace to replace the single quote with a
> other char. For that I use this xslt function:
>
> <xsl:template name="replace-string">
> <xsl:param name="text"/>
> <xsl:param name="replace"/>
> <xsl:param name="with"/>
> <xsl:choose>
> <xsl:when test="contains($text,$replace)">
> <xsl:value-of
> select="substring-before($text,$replace)"/>
> <xsl:value-of select="$with"/>
> <xsl:call-template name="replace-string">
> <xsl:with-param name="text"
> select="substring-after($text,$replace)"/>
> <xsl:with-param name="replace"
> select="$replace"/>
> <xsl:with-param name="with"
> select="$with"/>
> </xsl:call-template>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="$text"/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> This function works fine with all Chars except the ' ('). When I do
> a
>
> <xsl:call-template name="replace-string">
> <xsl:with-param name="text" select="normalize-space(/doc)"/>
> <xsl:with-param name="replace" select="'''"/>
> <xsl:with-param name="with" select="'"'"/>
> </xsl:call-template>
>
> I get this Error
>
> Invalid expression '''
> Compilation error: file ... element with-param
>
> And so on.
>
> I can introduce myself why this expression wrongly strike. But I have no
> answer.
>
>
> Regards,
> Oliver Feige
>
>
>
> --__--__--
>
> _______________________________________________
> xslt mailing list
> xslt@gnome.org
> http://mail.gnome.org/mailman/listinfo/xslt
>
>
> End of xslt Digest
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]