Using a complex url in xslt

Hi - this should be simple but of course never is.  I need to hardcode a url in xslt per the following simple example which works:

<xsl:variable name="URL" >
<a><xsl:attribute name="href"><xsl:value-of select="$URL"/></xsl:attribute>My Link</a>

However, if I atempt to use a Google map complex url string, it chokes on multiple "=" and "&" characters.  This happens also using  <xsl:variable name="url" select="'the url google string'" />.  It can't simply accept the string as-is without processing it I guess.

<xsl:variable name="URL" >

The Error message returned is:

Error: Error loading XSLT document.
XSLT compile error.'=' is an unexpected token. The expected token is ';'. Line 38, position 46. Line 38, position 46.
Line: 38
Position: 46

I'm a novice at this and just need to get it to work.

Who is Participating?
Geert BormansConnect With a Mentor Information ArchitectCommented:
there is really no need to url-encod this string.
it is not url decoding/encoding that i important but XML encoding
since the problem is originated at the xml parser, parsing the xslt

you should stuff the uri in a cdata section, than the parser doesn't bother about the &
        <xsl:variable name="URL" >
        <a><xsl:attribute name="href"><xsl:value-of select="$URL"/></xsl:attribute>My Link</a>

Open in new window

You have to URL-encode that string.
Richard__GAuthor Commented:
Thanks, but I get the following and it does not work:
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Richard__GAuthor Commented:
I tried this and it's a start, google maps comes up but the location is messed up somehow.  It brings up the US map and that's it.   Is there no way to simply have xsl treat it as a text string and not mess with it?
Richard__GAuthor Commented:
gave up. no solutions worked.
Geert BormansInformation ArchitectCommented:
it took you 9 months to understand that it didn't work and then give up?

please explain what doesn't work.
I am not sure how you tested my solution, if at all

I gave exactly the solution to your problem and it works at my end
My solution had been tested prior to posting, it worked back then, I just tested it again and it still works
using my code snippet gives a link in the resulting html
clicking the link leads me to the empire state building on google maps

CDATA sections are the answer to your problem, full stop

You should have asked more info when you were still experiencing problems, you still can by the way.
But I can't accept you to delete a question having a valuable working and tested solution as an answer
Richard__GAuthor Commented:
To be honest - I tried it, must have done it wrong, and gave up at that point.  No offence or insult was intended, my apologies, it was probably my fault. It was just one of many things I was dealing with at the time.

At this point I'd just like to delete the question.

Geert BormansInformation ArchitectCommented:
3) Accept: http:#a28386764

In the URL there is a string "&hnear="
An "&" starts an entity, and a limited set of tokens are allowed as characters in the name of the entity, "=" is not an allowed token
entity names end with a ";"
The parser is expecting a ";" instead of a "="
The "&" is not intended as an entity start but as the literal "&"
so it should be escaped for the XSLT to be wellformed
1. By using "&amp;" instead of "&" but that would require some work on the url
2. By wrapping the entire URL in a CDATA section as I did in the solution. Then a "&" is considered literal

Simple but effective answer to the problem stated
I recommend to keep it in the database (hence 4) since it is a common problem and the solution could be usefull to others
All Courses

From novice to tech pro — start learning today.