<!-- | PortableURLEncoderTest.xsl: Shows how to use Java extension functions | in a way that can work across different vendor's XSLT implementations +--> <xsl:stylesheet version="1.0" exclude-result-prefixes="xtUrl oracleUrl saxonUrl" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" xmlns:xtUrl ="http://www.jclark.com/xt/java/URLEncoder" xmlns:oracleUrl ="http://www.oracle.com/XSL/Transform/java/URLEncoder" xmlns:saxonUrl ="http://anythinghere/URLEncoder"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:variable name="urlBase">http://foo.com/SomeService</xsl:variable> <xsl:variable name="urlArgs" select="'company=at & t / mobilecom'"/> <xsl:variable name="quotedUrlArgs"> <!-- Invoking the xsl:call-template inside --> <xsl:call-template name="escapeURLArgs"> <xsl:with-param name="text" select="$urlArgs"/> </xsl:call-template> </xsl:variable> <!-- Output the URL as the concatentation of urlBase+"?"+quotedUrlArgs --> <xsl:value-of select="concat($urlBase,'?',$quotedUrlArgs)"/> </xsl:template> <xsl:template name="escapeURLArgs"> <xsl:param name="text"/> <xsl:choose> <!-- If xtUrl:EncodeURLArgs is available, then invoke it... --> <xsl:when test="function-available('xtUrl:EncodeURLArgs')"> <xsl:value-of select="xtUrl:EncodeURLArgs($text)"/> </xsl:when> <!-- If saxonUrl:EncodeURLArgs is available, then invoke it... --> <xsl:when test="function-available('saxonUrl:EncodeURLArgs')"> <xsl:value-of select="saxonUrl:EncodeURLArgs($text)"/> </xsl:when> <!-- If oracleUrl:EncodeURLArgs is available, then invoke it... --> <xsl:when test="function-available('oracleUrl:EncodeURLArgs')"> <xsl:value-of select="oracleUrl:EncodeURLArgs($text)"/> </xsl:when> </xsl:choose> </xsl:template> </xsl:stylesheet> |