使用XSLT 1.0进行URL编码

Gin*_*s K 6 xslt escaping character href

我在编写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>
Run Code Online (Sandbox Code Playgroud)

所以我需要将变量传递projectNumber给结尾myUrl.这很好用,我得到...myUrl...&projectNumber=...projectNumber...HTML.

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

例如,如果myUrl www.example.com/example.aspx?a=b和projectNumber是aaa?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是'ū'逃脱的方式)有什么建议吗?谢谢.

Nid*_*eph 10

如果您使用的是XSLT 1.0,请参阅此内容.

对于XSLT 2.0,您可以使用它来解决问题.

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