XSLT 版本 1 URL 编码 [英] XSLT version 1 URL encoding

查看:31
本文介绍了XSLT 版本 1 URL 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XSLT 版本 1 中是否有 URL 编码功能?我需要类似于 javascript 中的 encodeURIComponent 函数的东西?

Is there a URL encoding function in XSLT version 1? I need something similar to encodeURIComponent function in javascript?

这是不可能的,因为我使用的是 .NET 平台,因为 XSLT 应用于 Sharepoint 页面.有没有办法通过调用 XML 中的 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>

谢谢,

推荐答案

您可以使用嵌入在 XSLT 中的 JScript ...

you can use JScript embedded in XSLT ...

<msxsl:script language="JScript" implements-prefix="custom">
function uriencode(string) {
 return encodeURIComponent(string);
}
</msxsl:script>

并像custom:uriencode(url_to_encode)

您首先需要定义命名空间,方法是在 <xsl:stylesheet ... 标签中添加xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:custom="http://youdomain.ext/custom"

You will first need to define the namespace though by adding to the <xsl:stylesheet ... tag the xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:custom="http://youdomain.ext/custom"

[更新]

我为自定义命名空间设置的 URL 可以是任何东西 .. 它只是一个唯一标识符..
(该链接的结论是,如果您不使用网址作为标识符,就不会那么容易混淆..)

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..)

[更新日期 2]

添加了一些信息.
如果您使用 MSXML6,那么您需要使用 AllowXsltScript 属性手动允许在 XSLT 中编写脚本.. ( 参考 )
根据您加载 xslt 的方式及其设置,请查看 使用 msxsl:script 的脚本块 关于如何允许脚本

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

这篇关于XSLT 版本 1 URL 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆