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