[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] outputting an with a URL which contains "&func"


Subject: Re: [xsl] outputting an <a href> with a URL which contains "&func"
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 22 Jan 2002 10:28:28 +0000

Hi Saverio,

> I'm trying to output an <a href> from an XSL template.
> The value of the href attribute is a URL which contains the string
> ``&func''

You need to escape the & as &amp;. Try:

<a href="http://....?dtype=C&amp;func=front&amp;state=&amp;style=">
  ...
</a>

> The following results in an error regarding the reference to entity "func".
> The error states that the reference must end with the ';' delimiter.
>
> <a><xsl:attribute name="href"><xsl:text
> disable-output-escaping="yes">http://....?dtype=C&func=front&state=&style="></xsl:text>
> </xsl:attribute></a>
>
> I have been able to circumvent this error with the following code.
>
> <a><xsl:attribute name="href"><xsl:text
> disable-output-escaping="yes"><![CDATA[http://....?dtype=C&func=front&state=&style=]]></xsl:text>
> </xsl:attribute>

XSLT documents are XML documents. In XML, all ampersands in attribute
or element content must be escaped, either with &amp; or (for element
content) by wrapping the text within a CDATA section. Your second set
of code is exactly the same as:

<a><xsl:attribute name="href"><xsl:text
disable-output-escaping="yes">http://....?dtype=C&amp;func=front&amp;state=&amp;style=</xsl:text>
</xsl:attribute>

The disable-output-escaping that you're adding in the above is having
absolutely no effect on what you get in the result, by the way.
Disabling output escaping only works for the element content that you
generate, not for attribute values. So the above is exactly the same
as:

<a><xsl:attribute name="href">
<xsl:text>http://....?dtype=C&amp;func=front&amp;state=&amp;style=</xsl:text>
</xsl:attribute>

And of course any attribute with a fixed name can be added literally
instead of through xsl:attribute, if you want, so the above is exactly
the same as:

<a href="http://....?dtype=C&amp;func=front&amp;state=&amp;style=">

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread