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" >
      <xsl:text>http://www.google.com/</xsl:text>
</xsl:variable>
<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" >
<xsl:text>http://maps.google.com/maps?oe=&ie=UTF8&q=empire+state+bldg&fb=1&gl=us&hq=empire+state+bldg&hnear=New+York,+NY&cid=0,0,10486035129809466739&ei=l7moS-XDO8X7lwe61Nm3AQ&ved=0CA8QnwIwAA&ll=40.748964,-73.985367&spn=0.009607,0.018411&t=h&z=16&iwloc=A</xsl:text>
</xsl:variable>

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.

Richard__GAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

miahiCommented:
You have to URL-encode that string.

http://www.w3schools.com/TAGS/ref_urlencode.asp
0
Richard__GAuthor Commented:
Thanks, but I get the following and it does not work:

http%3A%2F%2Fmaps.google.com%2Fmaps%3Foe%3D%26ie%3DUTF8%26q%3Dempire%2Bstate%2Bbldg%26fb%3D1%26gl%3Dus%26hq%3Dempire%2Bstate%2Bbldg%26hnear%3DNew%2BYork%2C%2BNY%26cid%3D0%2C0%2C10486035129809466739%26ei%3Dl7moS-XDO8X7lwe61Nm3AQ%26ved%3D0CA8QnwIwAA%26ll%3D40.748964%2C-73.985367%26spn%3D0.009607%2C0.018411%26t%3Dh%26z%3D16%26iwloc%3DA
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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?
0
Geert BormansInformation 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" >
            <xsl:text><![CDATA[http://maps.google.com/maps?oe=&ie=UTF8&q=empire+state+bldg&fb=1&gl=us&hq=empire+state+bldg&hnear=New+York,+NY&cid=0,0,10486035129809466739&ei=l7moS-XDO8X7lwe61Nm3AQ&ved=0CA8QnwIwAA&ll=40.748964,-73.985367&spn=0.009607,0.018411&t=h&z=16&iwloc=A]]></xsl:text>
        </xsl:variable>
        <a><xsl:attribute name="href"><xsl:value-of select="$URL"/></xsl:attribute>My Link</a>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard__GAuthor Commented:
gave up. no solutions worked.
0
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
0
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.

0
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 "="
BUT
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.