RE: [xsl] : Escaping '&' in an HTML link.

Subject: RE: [xsl] : Escaping '&' in an HTML link.
From: "Robert C. Lyons" <boblyons@xxxxxxxxxx>
Date: Mon, 30 Jul 2001 21:43:56 -0400
Aparna,

Your XSLT stylesheet can invoke the encode method of the
java.net.URLEncoder class.

The encode method would convert "Star&Buck" to "Star%26Bucks".
The method would encode other non-alphanumeric characters
as well. For example, it would also encode "Don't go!" as
"Don%27t+go%21".

For more information about the URLEncoder class, please see:

http://java.sun.com/products/jdk/1.1/docs/api/java.net.URLEncoder.html

Hope this helps.

Bob

<sig name    = 'Bob Lyons'
     title   = 'XML Consultant'
     company = 'Unidex, Inc.'
     phone   = '+1-732-975-9877'
     email   = 'boblyons@xxxxxxxxxx'
     url     = 'http://www.unidex.com/'
     product = 'XML Convert: transforms flat files to XML and vice versa' />

-----Original Message-----

Hello,

Here is my stylesheet (basic structure):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:param name="address">index.jsp</xsl:param>
<xsl:output method="html" indent="yes" />

<xsl:template match="AAA">

    <html>
       <head>
         <title>TITLE</title>
       </head>
       <body >
		<form method="POST" name="index" action="{$address}">
                Your request: <input type="text" name="query"
size="15"></input>
                          <input type="submit" name="go" value="GO"></input>
			............
        		<a>
				<xsl:attribute name="href">
					<xsl:value-of
select="$address"/>?query=Edit+name+<xsl:value-of
select="translate(normalize-space(groupName),' ','+')"/>
				</xsl:attribute>
			<a>
			............
		</form>
       </body >
    </html>
</xsl:template>
.......


But this link fails when it encounters a value with "&" in it e.g.
Star&Bucks fails because of the '&' in between.
Is there any to escape the '&' so that the URL is completely and properly
formed?
I tried "disable-output-escaping" but it didnot seem to work.

Thanks in anticipation for any help provided.

Aparna


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread