Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1409
  • Last Modified:

XSL ampersand in the url

Ok, This is my 3rd day working with xml and I've read and read posts on how to accomplish this and still can't get it to work correctly.

I have an image tag that is dynamic.  The src= line posts to a funky .asp page that fetches the correct image and displays it.

If I paste this in my xsl file it works fine.

<IMG src="https://docs.myserver.com/wx/MCGetDoc.asp?s=s&a=2&i=453621&d=ID:+STUDENT+PHOTO" width="150" height="200" border="0" />

the problem comes in when I attempt to change the value of i= in there.  That is supposed to be the id number of the record I'm displaying other info about (<xsl:value-of select="IDNumber"/>)

I've attmepted to break it apart into element and attributes but then it complains about the apersand whether I use it straight or use &amp;

Any ideas ?
  • 2
  • 2
1 Solution
Hi netlurch,

Based on your code:

<IMG src="https://docs.myserver.com/wx/MCGetDoc.asp?s=s&a=2&i=453621&d=ID:+STUDENT+PHOTO" width="150" height="200" border="0" />

There are two ways you can accomplsih this:

<IMG width="150" height="200" border="0">
  <xsl:attribute name="src">
<xsl:value-of select="IDNumber"/>

<IMG width="150" height="200" border="0"
src="https://docs.myserver.com/wx/MCGetDoc.asp?s=s&a=2&i={<xsl:value-of select="IDNumber"/>}&amp;d=ID:+STUDENT+PHOTO" />

Hope this would help.  Good luck!
netlurchAuthor Commented:
Thanks for the suggestions, I tried both of these.

The first one with the attribute I get this :

"This is an unexpected token. Expected 'SEMICOLON'. Line 77, position 48"

This is the line with the https://... in it and its catching in the &amp;s.  If I take them out it 'works'  doesn't pull the image, but no error.

The second example gives this message :
"'<', hexadecimal value 0x3C, is an invalid attribute character. Line 75, position 108." which I believe is the beginning of the <xsl... tag

Those were both great ideas, I had attempted something similar to both and was getting the same errors, I just figured it was because I was a newbie.
Hi netlurch,

I checked through the codes again, and found out I have made a mistake on the second case.  Sorry about that.  Also, I added "//" on your IDNumber to correctly locate the element.  As for the first case, try not to include any unnecessary lines or space.  

The following should be the proper way:

<IMG width="150" height="200" border="0"><xsl:attribute name="src">https://docs.myserver.com/wx/MCGetDoc.asp?s=s&a=2&d=ID:+STUDENT+PHOTO&i=<xsl:value-of select="//IDNumber"/></xsl:attribute></IMG>

<IMG width="150" height="200" border="0" src="https://docs.myserver.com/wx/MCGetDoc.asp?s=s&a=2&i={//IDNumber}&amp;d=ID:+STUDENT+PHOTO"/>

And just in case if you haven't already done so, these code need to sit within the main template:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:template match="/">
...your code here...

Good luck.
netlurchAuthor Commented:

First one still doesn't work .... but the second one works like a charm !

Thanks for all the help !


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now