Good suggestions, but you can actually do this with OXF today:

<xsl:stylesheet xmlns:net="http://orbeon.com/oxf/xslt/net>
  <xsl:import href="oxf:/oxf/xslt/utils/utils.xsl"/>
  ...
    <xsl:value-of select="net:encode-url($url)"/>

This is not documented and subject to change though. It will only work
with Xalan. You can also directly call Java code (declare
xmlns:java="http://xml.apache.org/xslt/java). Again, this is the
syntax for Xalan:

<xsl:value-of select="java:java.net.URLEncoder.encode($value)"/>

EXSLT defines a function, str:encode-uri, that probably does the same
thing, but it does not appear to be implemented in Xalan.

-Erik

Damon Rand wrote:

> While I am making requests for extensions.. ;-)
>
> Today I needed to URLEncode a string.. In the end I got an XSLT urlencode
> function off the web.. However it seems to me that there are some situations
> (such as string manipulation and math) where it is just much more sensible
> to drop down to Jscript.. I know I could call a webservice or use the Java
> processor but JScript seems convenient for simple tasks.
>
> Two possible ideas..
>
> 1. Msxml has a nice extension function that lets you do JScript in xslt.. Is
> there anything similar in the Java xslt engines used in OXF?
>
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>  xmlns:user="user"
>  exclude-result-prefixes="msxsl user">
>
>  <msxsl:script language="JavaScript" implements-prefix="user">
>   <![CDATA[
>    function encodeString(str_in) {
>     return escape(str_in);
>    }
>   ]]>
>  </msxsl:script>
>
>  <xsl:template name="urlEncode">
>   <xsl:param name="text" />
>   <xsl:value-of select="user:encodeString(string($text))" />
>  </xsl:template>
>
> </xsl:stylesheet>
>
> 2. I guess the OXF way would be a JScriptProcessor though.. This example
> would be analagous to the xupdate processor except the transformation would
> be via JScript. eg.
>
> <?xml version="1.0"?>
> <p:processor uri="oxf/processor/jscript"
> xmlns:p="http://www.orbeon.com/oxf/pipeline";>
>  <p:input name="config"><![CDATA[
>
>     function encodeString(str_in) {
>      return escape(str_in);
>     }
>
>     var xDocument = this.readInputAsDom('data');
>     var xText = xDocument .selectSingleNode('/string/text()');        //
> forget the exact syntax right now
>     xText.value = encodeString(xText.value);
>
>    ]]></p:input>
>  <p:input name="data">
>   <string>some text to urlencode!</string>
>  </p:input>
>  <p:output name="data" id="output" />
> </p:processor>
>
>
> Damon.


_______________________________________________ oxf-users mailing list [EMAIL PROTECTED] http://mail.orbeon.com/mailman/listinfo/oxf-users

Reply via email to