Percent-encoding using XSLT 1.0

自古美人都是妖i 提交于 2019-12-02 19:08:34

问题


I am using XSLT 1.0 and I am not supposed to use XSLT 2.0. I have the following xml in which the value of <prvNum> has some special characters.

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <prvNum>SPECIAL#1&amp;</prvNum>
</root>

Now I want to perform percent-encoding for the value of <prvNum>. For example the value should be changed as below after percent encoding:

SPECIAL%231%26

I am trying with the following code snippet, but the stylesheet is not compiling.

 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="http://youdomain.ext/custom" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
   <msxsl:script language="JScript" implements-prefix="custom">function uriencode(string) {
 return encodeURIComponent(string);
}</msxsl:script>
   <!-- identity template -->
   <xsl:template match="@*|node()">
      <xsl:copy>
         <xsl:apply-templates select="@* | node()" />
      </xsl:copy>
   </xsl:template>
   <xsl:template match="prvNum">
      <prvNum>
         <xsl:copy-of select="@*" />
         <xsl:value-of select="custom:uriencode(text())" />
      </prvNum>
   </xsl:template>
</xsl:stylesheet>

Can anybody help me to fix the issue?

来源:https://stackoverflow.com/questions/42158893/percent-encoding-using-xslt-1-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!