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

translate for partial uri-encoding?

Subject: translate for partial uri-encoding?
From: "Jeff Greif" <jgreif@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 8 Sep 2004 21:02:43 -0700
xsl translate
Suppose I have this input document

<company>JOE'S PAINT &amp; BODY<company>

and I'm trying to insert the element's text in the query string of a URI in
a result document, doing something like this

<xsl:template match="/">
   <someURL>
       <xsl:text>xsl:text>http://foo.com/?X=1&amp;CO=</xsl:text>
       <xsl:value-of select="translate(/company, ' ', '+')"/>
    </someURL>
</xsl:template>

The result document should look like:
<someURL>http://foo.com/?X=1&amp;CO=JOE%27S+PAINT+%26+BODY</someURL>

The translate function arguments above are insufficient to correctly
url-encode the text of the input <company> node given above (as written, it
only converts space to +).  The proof-of-concept demo I'm producing in a
very limited time will run on an XSLT platform that does not support *any*
extensions (such as the EXSLT str:encode-uri), so I'm trying to get by with
xsl:translate.  For this demo, I have some control over what input will
actually be passed, but must at least appear to have some idea of what I'm
doing for common cases with unsafe characters.

What is the trick for including the ampersand and apostrophe characters in
the 2nd argument of the translate function and their encoded equivalents in
UTF-8 (e.g. %26 for the ampersand) in the third argument of translate?  I'm
not ambitious enough to attempt to handle all the unsafe characters that can
occur in all possible character encodings, or even all such characters in
one encoding.

Jeff

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.