Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] special characters replaced in javascript url

From: "Mingqiang Yu" <myu@-------->
To:
Date: 10/22/2005 4:59:00 AM
I have a problem which was asked a while ago but I couldn't find the final
answer to that question. So I'm sorry that I have to raise this question
again.(http://lists.xml.org/archives/xml-dev/200310/msg00841.html)

I have a very similar problem in which, I have an xml record passed to my
stylesheet which contains the following string:
Cr&eacute;mieu, V.
So, in order for the stylesheet to handle this special characters
correctly, I need to defined it in my dtd file(document.dtd) like this:
<!ENTITY eacute  "&#233;" >
and include this dtd file in the xml file passed to the stylesheet:
<!DOCTYPE document  SYSTEM "document.dtd" >

Then, the special characters are displayed correctly but when I tried to
pass it as part of the url through javascript:
<a href="javascript:frLink('FRLink','author',&quot;{$thisTerm}&quot;);">
in which the $thisTerm is the string Cr&eacute;mieu, V., the same string
becomes "Cr%C3%A9mieu, V".

I tried to use the solution introduced in the link above by doing
escape-javascript like this:
<xsl:template name="escape-javascript">
    <xsl:param name="string" />
    <xsl:choose>
        <xsl:when test='contains($string, "&#233;")'>
            <xsl:call-template name="escape-javascript">
                <xsl:with-param name="string"
select='substring-before($string, "&#233;")' />
            </xsl:call-template>
            <xsl:text>&amp;eacute;</xsl:text>
            <xsl:call-template name="escape-javascript">
                <xsl:with-param name="string"
select='substring-after($string, "&#233;")' />
            </xsl:call-template>
        </xsl:when>
        <!-- test for other special characters or entities here -->
        <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
    </xsl:choose>
</xsl:template>

It seems to work for this case. But I have too many special characters
that I cannot do the escape for every special characters.

Can you help to find a better solution to solve this problem?

Thanks in advance.

Ming


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent