This is driving me insane - I have an xslt file that contains some dynamic javascript based on child nodes which i'm looping around. I need to add a link to the end of the following javascript string:-
var myHtml = "<b><xsl:value-of select="./@nodeName"/></b>" +
LINK NEEDED HERE (something like "<a href='<xsl:value-of select="./data [@alias = 'url']"/>'>click me</a>" +
"</ul>";
The problem is the link URL needs to be pulled from the node but i can't for the life of me get the <a href> working. I believe the problem lies with the quotes - I've tried escaping the quotes but i get errors, I've tried using JavaScript variables but no luck. I either get xslt parse errors or JavaScript errors. I can't think of anything else to try, any suggestions would be great.
I think i just need the single quotes around Operational and it should work. I tried &apos and ' instead but the parser doesn't like it, but it's ok with " !!!
Add URL to a string in Javascript/xslt
This is driving me insane - I have an xslt file that contains some dynamic javascript based on child nodes which i'm looping around. I need to add a link to the end of the following javascript string:-
var myHtml = "<b><xsl:value-of select="./@nodeName"/></b>" +
"<br /><ul>" +
"<li><b>Capacity: </b> <xsl:value-of select="./data [@alias = 'capacityText']"/></li>" +
"<li><b>Location: </b> <xsl:value-of select="./data [@alias = 'locationText']"/></li>" +
"<li><b>Project Status: </b> <xsl:value-of select="./data [@alias = 'projectStatus']"/></li>" +
LINK NEEDED HERE (something like "<a href='<xsl:value-of select="./data [@alias = 'url']"/>'>click me</a>" +
"</ul>";
Aron
Aron,
try
Ismail
That's exactly what i want to do but the xslt parser doesn't like it..
I tried adding this:-
"<a href='{./data [@alias = 'URL']}'>" +
but i get the following xslt error:-
System.Xml.XmlException: 'locationText' is an unexpected token. Expecting white space. Line 103, position 32.
Bugger..
Aron
Try replacing the ' quotes with escaped double quotes eg \"
I think it has to do with the doubling up of single-ticks. Try using double quotes and escaping them for the outer so it would look like this:
"<a href=\"{./data [@alias='locationText']}\">"
HTH,
Nik
Hi
I tried this:-
"<a href=\"{./data [@alias = 'url']}\"/>click me</a>"
But get this xslt error:-
System.Xml.XmlException: '\' is an unexpected token. The expected token is '"' or '''. Line 103, position 14.
It seems like the parser doesn't like the fact were trying to escape the double quote for some reason.
Aron
What about using HTML encoded quotes?
"
Matt
Oops, got encoded on my phone.
"
matt
Or, if possible, please wrap your script contents in a CDATA tag.
Thanks for the responses..
Matt - i tried " and the xslt parser doesn't like the ampersand
Nik - Won't CDATA just spit out everything literally including the xsl tags etc. ?
Thanks again.
Aron
Hi Aron,
Try this...
I've used the concat() function to escape the <a> tag. Let me know if it works out.
Cheers, Lee.
Snazzy Lee! I like that...
Lee
We're almost there!
I took your example and added quotes around the line with the link so the whole thing looks like this:-
var myHtml = "<b><xsl:value-of select="@nodeName"/></b>"
+ "<br /><ul>"
+ "<li><b>Capacity: </b><xsl:value-of select="data[@alias='capacityText']"/></li>"
+ "<li><b>Location: </b><xsl:value-of select="data [@alias='locationText']"/></li>"
+ "<li><b>Project Status: </b><xsl:value-of select="data[@alias='projectStatus']"/></li>"
+ "<xsl:value-of select="concat('<a href="', data[@alias='projectStatus'], '">click me</a>')" disable-output-escaping="yes" />"
+ "</ul>";
Try putting slashes in-front of the double-quotes. (I'm stealing Ismail's suggestions now) ;-)
That will escape them in the outputted JavaScript.
Failing this... there is an alternative - and that's mixing in-and-out of <xsl:text> tags - it looks horrid, but it will work.
Cheers, Lee.
Lee
That seems to have done it!
The section gets rendered like this:-
Glad to see it working. Aren't you missing the <li> around the link though? Just a thought...
Well spotted - I'll tidy it up and put the <li> tags in.
Cheers
Aron
is working on a reply...