Okay, because this keeps coming up,
This means that when XSL outputs URLs like:
it is not a bug that there’s a ”&” in there!. In fact, this URL is more spec-compliant than a URL that simply contains ”&“.
The breakdown goes something like this:
- HTTP and URI’s declare that the ampersand is used to separate name/value pairs for GET-type form submissions.
- SGML and XML specify that “special characters” need to be escaped into their character entities when they occur inside attributes in elements. Unfortunately, the ampersand is the character that denotes the beginning of a character entity, and is thus considered a “special character.”
- This means that the ampersand must be represented as
&if it occurs inside an
hrefattribute in the
Atag for the HTML to be truly valid. This is a hard requirement for XHTML validation.
An interesting corollary happens if you live in the XSL world, like I do. If you create your links in XSL like this:
then ampersands will always be escaped into their entity form. However, if you create your links like this:
1<a>2<xsl:attribute name="href">3 <xsl:value-of select="$my_link_var_with_ampersands"4 disable-output-escaping="true" />5</xsl:attribute>6</a>
an interesting thing occurs. If your output method is set to “text/html”, then the XSLT engine will output escaped ampersands. If you output method is set to “text/plain”, then it will not, since the engine is not worried about producing code to SGML/XML specs.