First I have to state that I touched XSLT today for the first time because a friend asked me for help.
We’re trying to generate a link for GMaps. Everything works as long as there is no space in the variable we’re using. Here’s the code.
<xslt:template name="buildmaps">
<xslt:param name="linkstart"/>
<xslt:param name="link_target_street"/>
<xslt:param name="link_target_postalcode"/>
<xslt:param name="link_target_city"/>
<xslt:param name="linktext"/>
<xslt:param name="target"/>
<xslt:text disable-output-escaping="yes"><a href=http://maps.google.de/maps?hl=de&saddr=Hauptstr.%2057%2044789%20Bochum</xslt:text>
<xslt:text disable-output-escaping="yes">&daddr=</xslt:text>
<xslt:value-of select="$link_target_street"/>
<xslt:text disable-output-escaping="yes">%20</xslt:text>
<xslt:value-of select="$link_target_postalcode"/>
<xslt:text disable-output-escaping="yes">%20</xslt:text>
<xslt:value-of select="$link_target_city"/>
<xslt:text disable-output-escaping="yes">" target="</xslt:text>
<xslt:value-of select="$target"/>
<xslt:text disable-output-escaping="yes">"></xslt:text>
<xslt:value-of select="$linktext"/>
<xslt:text disable-output-escaping="yes"></a></xslt:text>
</xslt:template>
The problem occurs with the $link_target_street variable. Which looks like “Bahnhofstr. 9”. We get our link allright like “http://maps.google.de/…daddr=Hauptstr.”. So everything stops at the blank between Hauptstr. and 9.
Is there something I can do about it?
Thx in advance.
Update:
Now I know I’m using XSLT 1.0. So no replace for me 🙁
Now a bit about the output:
It should look like this:
<a href="http://maps.google.de/maps?hl=de&saddr=Hauptstr.%2057%2044789%20Bochum&daddr=Mainstreet%2023%2012345%20Bochum" target="_blank">
The problem lies in the street name. There I get:
... &daddr=Mainstreet 23%2012345%20Bochum" ...
but I need
... &daddr=Mainstreet%2023%2012345%20Bochum" ...
At this point I’m not sure if XSLT really stops at this blank or if the Url is just too broken to get handled properly. Either way if I could change the blank to ‘%20’ everything would be fine. I think probably the links from Tomalak will help me out.
Unfortunately I’m at home now and have to set up a test environment myself but we found the debug option so I hope that will fasten the process.
Looks like you are shooting yourself in the foot.
Note that there are Attribute Value Templates.
Further, XSLT has no built-in function to do URL-encoding. However, that is what you need to do when you want to place arbitrary values into a URL.
There are a few methods to make a URL-encoding function available to XSLT, it depends on your XSLT processor which one would work for you.