[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: url encoding of ampersands

Subject: Re: url encoding of ampersands
From: Mike Brown <mike@xxxxxxxx>
Date: Sun, 25 Feb 2001 12:36:17 -0700 (MST)
xml url encoding
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.