This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: url encoding of ampersands


Sivan Mozes wrote:
> Description: 
> A link is pointing to an anchor, whose name contains an
> accented character. The URL is constructed based on a text node in the
> XML to avoid using special characters in an attribute. Next, the
> stylesheet needs to replace all ampersands with %26 for URL
> encoding.
> 
> Example:
> 
> XML:
> <link type="anchor">Cr&#233;pe</link>
> 
> Expected result:
> <a href="#Cr%26#233;pe">Cr&#233;pe</a>

According to http://www.w3.org/TR/html401/appendix/notes.html#h-B.2
you really want:

<a href="#Cr%C3%A9pe">Cr&#233;pe</a>
or
<a href="#Cr%C3%A9pe">Cr&eacute;pe</a>

Though if %C3%A9 doesn't work, and if your output encoding is iso-8859-1 or
windows-1252, try %E9.

> Template:
> <xsl:template match="link">
>   <xsl:variable name="anchor" select="concat(substring-before( . ,
> '&amp;'), '%26', substring-after( . , '#'))"/>

This won't work because there is no ampersand in your *source tree* (which
was *derived* from your original XML). &#233; in your XML is resolved by
the XML parser into a single LATIN SMALL E WITH ACUTE character long before
the XSLT processor sees it. Likewise, your output will be *derived* from
the result tree you construct, hence the automatic conversion of the
character in question into &eacute; or &#233; by the XSLT processor's
result tree serializer, just as it would convert an ampersand into &amp;.

<xsl:variable name="anchor" select="concat(substring-before(.,'&#233;'),
'%C3%A9',substring-after(.,'&#233;'))"/>

   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at            My XML/XSL resources: 
webb.net in Denver, Colorado, USA              http://skew.org/xml/


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]