Is there a URL encoding function in XSLT version 1? I need something similar to encodeURIComponent function in javascript?
Seeing as this is not possible as I'm using .NET platform as the XSLT is applied to a Sharepoint page. Is there a way to code this buy calling the javascript encode function within the XML, snippet below:
<xsl:template name="BuildLink">
<xsl:param name="PrimarySubject" />
<xsl:text>?PrimarySubject=</xsl:text>
<xsl:value-of select="$PrimarySubject" />
</xsl:template>
Thanks,
you can use JScript embedded in XSLT ...
and call it like
custom:uriencode( url_to_encode )
You will first need to define the namespace though by adding to the
<xsl:stylesheet ...
tag thexmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:custom="http://youdomain.ext/custom"
[update]
the Url i put for the custom namespace could be anything .. it is just a unique identifier..
(the link concludes that it is less confusing if you do not use a url as the identifier..)
[udpdate 2]
Some added info.
If you use MSXML6 then you need to manually allow scripting in the XSLT, by using the
AllowXsltScript
property.. ( reference )Depending on the way you load the xslt and its settings have a look at the examples at Script Blocks Using msxsl:script on how to alow scripts
There isn't one. XSLT has no knowledge of URLs and HTML.
Depending on the language and platform you are using, you may be able to use a XSLT extension that does that.
These XSLT 1.0 stylesheets can be used to perform URL encode/decode:
You can, under certain circumstances use EXSLT (parser-provided extensions): Dave Pawson's XSLT FAQ on this one.
However, XSLT is Turing complete, so you could write a basic URL encoder in XSLT itself, theoretically (I wouldn't try).