Subject: RE: [xsl] translate for partial uri-encoding? From: "Michael Kay" <mhk@xxxxxxxxx> Date: Thu, 9 Sep 2004 08:36:36 +0100 |
There is no trick. You either write the code yourself, which you seem to be unwilling to do, or you invoke a library routine that does it, which you also seem unwilling to do. XPath 2.0 offers an encode-uri() function as standard, I suggest that if you are short of time you should use it. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Jeff Greif [mailto:jgreif@xxxxxxxxxxxxxxxxxxxx] > Sent: 09 September 2004 05:03 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] translate for partial uri-encoding? > > Suppose I have this input document > > <company>JOE'S PAINT & 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&CO=</xsl:text> > <xsl:value-of select="translate(/company, ' ', '+')"/> > </someURL> > </xsl:template> > > The result document should look like: > <someURL>http://foo.com/?X=1&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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] translate for partial uri-enc, Jeff Greif | Thread | Re: [xsl] translate for partial uri, David Carlisle |
RE: [xsl] Dynamic output encoding, Michael Kay | Date | RE: [xsl] Keys, Michael Kay |
Month |