Assuming you're outputting HTML (or XML), there's actually nothing wrong with the ampersands in your URL - in fact, it's how you're supposed to write an ampersand in HTML & XML.
Before the XSLT file is handed to the XSLTProcessor it's "just" an XML file which gets parsed by an XML parser. One of the tasks that the parser takes care of, is resolving entity references to their actual characters/expansions - you can try that in Internet Explorer, by creating a simple XML document like this:
<?xml version="1.0"?>
<title>Thelma & Louise</title>
Save that as "movie.xml" and open it in Internet Explorer - the default XML rendering in IE shows you how the XSLT Processor will see the document after being parsed by the XML parser. See the ampersand entity has been resolved? (And by the way - to the XSLT Processor there's no difference between & and & (or & for that matter) - they all result in the same character when resolved - try them in the little XML above...)
If you're generating HTML or XML, you'll want the XSLT Processor to handle the escaping for you in the output too, so that characters which needs escaping gets escaped in the output.
Agreed, there are times when you would want to output without escaping the various characters (mostly when converting text to actual HTML) which is what the disable-output-escaping attribute is for.
Ampersand in XSLT
Hi,
I've googled this and I'm sure I've done it before but I can't remember how!
I'm generating a url in XSLT which has query string parameters but with the XSLT escaping I can't get it to work.
My XSLT produces:
How can I turn this & into just & ?
Thanks!
Phew - done it.
For anyone else with this problem, the solution is to store the URL as a variable, then output it disablig output escaping.
ie.
If there's a better method I'd still be interested to know though!
You could try
For more see http://www.w3schools.com/tags/ref_entities.asp
Dan
Hi Edward,
Assuming you're outputting HTML (or XML), there's actually nothing wrong with the ampersands in your URL - in fact, it's how you're supposed to write an ampersand in HTML & XML.
Before the XSLT file is handed to the XSLTProcessor it's "just" an XML file which gets parsed by an XML parser. One of the tasks that the parser takes care of, is resolving entity references to their actual characters/expansions - you can try that in Internet Explorer, by creating a simple XML document like this:
Save that as "movie.xml" and open it in Internet Explorer - the default XML rendering in IE shows you how the XSLT Processor will see the document after being parsed by the XML parser. See the ampersand entity has been resolved? (And by the way - to the XSLT Processor there's no difference between & and & (or & for that matter) - they all result in the same character when resolved - try them in the little XML above...)
If you're generating HTML or XML, you'll want the XSLT Processor to handle the escaping for you in the output too, so that characters which needs escaping gets escaped in the output.
Agreed, there are times when you would want to output without escaping the various characters (mostly when converting text to actual HTML) which is what the disable-output-escaping attribute is for.
/Chriztian
Thanks for the replies!
I've tried the two suggested approaches but the approach I described before is the only one that works as required.
@dandrayne - I've tried putting this in my XSLT but the link produces still comes out as http://www.mysite.com/page?param1=1&param2=2
@Chriztian - I think maybe you misunderstood my requirements. Thanks for the in depth response about XML parsing standards though!
This worked for me (rather than method="xml")
is working on a reply...