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?
 
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" >
            <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
 
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
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?
0
 
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
All Courses

From novice to tech pro — start learning today.