RE: [xsl] generating ampersand for html "a href="

Subject: RE: [xsl] generating ampersand for html "a href="
From: "Clapham, Paul" <pclapham@xxxxxxxxxxxxx>
Date: Wed, 31 Jan 2001 13:36:41 -0800
I hear there's nothing wrong with having &amp; in your link.  Does it not
work in your browser?  Try it.


-----Original Message-----
From: Robert Gretta [mailto:robert.gretta@xxxxxxxx]
Sent: January 31, 2001 13:19
To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
Subject: [xsl] generating ampersand for html "a href="


I've been using xsl about a month and i've come across a case that I wish to
generate an html link that looks like.

<a href="page?param=val&param2=val2>

I thought that this would be a pretty basic thing. And i have 2 xsl books
and various resources but have yet to find a clear answer on how to format
such a monster without it getting hairy. So, I've just broken down and
decided to ask.

I've tried many things to get the "&" to come out not as an "&amp" but the
only thing that succeeds is xsl:value-of with disable-output-escaping.
interestingly i have no problem generating <% symbols.

here is a code snippet that will better describe my dilemma.

	<xsl:output method="html" /> <!-- note that output method is HTML

	<xsl:variable name="aand"><![CDATA[&]]></xsl:variable>
	<xsl:variable name="jsp-begin"><![CDATA[<% ]]></xsl:variable>
	<a href="{$jsp-begin} {$aand}" />

     the output is:

	<a href="<% &amp;" /> 

     but i want 

	<a href="<% &" />

I cannot understand why the "<%" comes through and the "&" gets
translated... unless this is an Xalan problem.

I had hoped that setting the output method=html would not translate the & in
a CDATA statement but hey, what do i know?

I had created a template to format the href and passed the href in as a
parameter when i noticed this quirk. 

	<xsl:template name="format-href">
		<xsl:param name="href"	></xsl:param>

		<a href="$href" />

     the output is:

	<a href="<% &amp;" /> 

the way to fix the template is something like the following... which seems
like overkill.

	<xsl:template name="format-href">
		<xsl:param name="href"	></xsl:param>

		<![CDATA[<a href="]]><xsl:value-of select='$href'

   the output is

		&lt;a href="<%&/"&gt;

which is still wrong... or i consider it to be wrong since i think that the
CDATA sections should protect the characters from being translated.

    Q: Is there a better way to build an href and pass it around
(xsl:call-template... xsl:with-param) without it being translated?
    Q: Is there a way to tell the processor not to translate (escape) the
CDATA sections?
    Q: Should I be using a different output method? 
    Q: Should I be using the "cdata-section-elements" attribute of
"xsl:output" ?

Any help would be appreciated.

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread