XSLT 1.0中的URL编码

7

我遇到了写XSL的问题。我有一个链接,代码如下:

<a>
<xsl:attribute name="href">
  <xsl:value-of select="concat($myUrl,'&amp;projectNumber=',$projectNumber)"/>
</xsl:attribute>
<xsl:attribute name="title">
  <xsl:value-of select="title"/>
</xsl:attribute>
LINK
</a>

所以我需要将变量projectNumber传递到myUrl的末尾。这很好用,我在HTML中得到了...myUrl...&projectNumber=...projectNumber...
问题是,变量projectNumber有时会有一些字符,在我的链接href中必须进行转义。我尝试使用XSL函数str:escape-uri()以多种不同的方式,但仍然没有成功...
例如,如果我的URL是www.example.com/example.aspx?a=b,而projectNumberaaaūaaa,我得到的href类似于www.example.com/example.aspx?a=b&projectNumber=aaaūaaa,但我需要得到www.example.com/example.aspx?a=b&projectNumber=aaa%C5%ABaaa。(%C5%AB是'ū'转义的方式)有什么建议吗?谢谢。
1个回答

11

如果你正在使用XSLT 1.0版本,那么请参考此链接

对于XSLT 2.0版本,您可以使用此方法来解决该问题。

<xsl:value-of select="concat($myUrl,'&amp;projectNumber=',encode-for-uri($projectNumber))"/>

尝试使用“encode-uri”而不是“encode-for-uri”运行相同的代码,但两种方式仍然无法正常工作 :/ - Gintas K
不,我还没有尝试过。你能否给我展示一个例子,如何将projectNumber传递到嵌入式JScript中并返回转义后的projectNumber? - Gintas K

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接