【问题标题】:URL encoding with XSLT 1.0使用 XSLT 1.0 进行 URL 编码
【发布时间】:2013-07-10 11:52:32
【问题描述】:

我在编写 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...&amp;projectNumber=...projectNumber...

问题是,变量projectNumber 有时有一些字符必须在我的链接的href 中转义。我尝试以多种不同的方式使用 XSL 函数str:escape-uri(),但仍然没有成功...

例如,如果 myUrl 是 www.example.com/example.aspx?a=b 而 projectNumber 是 aaaūaaa 我得到像www.example.com/example.aspx?a=b&amp;projectNumber=aaaūaaa 这样的href,但我需要得到www.example.com/example.aspx?a=b&amp;projectNumber=aaa%C5%ABaaa。 (%C5%AB 是 'ū' 的转义方式)有什么建议吗?谢谢。

【问题讨论】:

    标签: xslt escaping character href


    【解决方案1】:

    如果您使用的是 XSLT 1.0, 然后参考this

    如果是 XSLT 2.0,您可以使用它来解决问题。

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

    【讨论】:

    • 用 'encode-uri' 而不是 'encode-for-uri' 尝试了相同的代码,但它仍然不能双向工作:/
    • 不,我没试过,你能告诉我一个例子如何将 projectNumber 传递给嵌入式 JScript 并返回转义的 projectNumber?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 2016-01-25
    • 1970-01-01
    • 2015-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多