关于XSL与JS通信的问题
时间:2008-06-12
来源:互联网
我用些数据是使用XSL生成的<xsl:value-of select="SearchResult/Info/Key"/>--这是数据
<input type="button" onclick= 'changePage()' value="确定" /> -- 这是要通信的地方
我怎么样才可以让changePage(<xsl:value-of select="SearchResult/Info/Key"/>)这样的一个效果?
我如果是直接按上述changePage(<xsl:value-of select="SearchResult/Info/Key"/>)这样的写法就会出错有人知道我需要怎么处理吗
-----------------JSCode------------------------------
<![[CDATA
function changePage(content){
var pnum = document.getElementById('pgnum').value;
var content = document.getElementById('keyword').value;
if(!isNaN(pnum)){
window.location = 'http://s.gv365.com:8080/VSEngine/SearchEngine?qs=1&pg='+pnum+'&template='+content;
}else{
alert('请输入有效的数字...');
return false;
}
}
]]>
---------------------------------------------------------------
[[i] 本帖最后由 xjfseasky 于 2008-6-12 17:46 编辑 [/i]]
<input type="button" onclick= 'changePage()' value="确定" /> -- 这是要通信的地方
我怎么样才可以让changePage(<xsl:value-of select="SearchResult/Info/Key"/>)这样的一个效果?
我如果是直接按上述changePage(<xsl:value-of select="SearchResult/Info/Key"/>)这样的写法就会出错有人知道我需要怎么处理吗
-----------------JSCode------------------------------
<![[CDATA
function changePage(content){
var pnum = document.getElementById('pgnum').value;
var content = document.getElementById('keyword').value;
if(!isNaN(pnum)){
window.location = 'http://s.gv365.com:8080/VSEngine/SearchEngine?qs=1&pg='+pnum+'&template='+content;
}else{
alert('请输入有效的数字...');
return false;
}
}
]]>
---------------------------------------------------------------
[[i] 本帖最后由 xjfseasky 于 2008-6-12 17:46 编辑 [/i]]
作者: xjfseasky 发布时间: 2008-06-12
解决.
这里只能使用JS去get xsl INPUT CONTNENT的信息.
这里只能使用JS去get xsl INPUT CONTNENT的信息.
作者: xjfseasky 发布时间: 2008-06-13
你的SearchResult/Info/Key是不是纯数字,如果不是纯数字就应该用引号引起来,可以直接用单引号,或者双引号的转义"
如果你的SearchResult/Info/Key里面含有引号那么还要对引号进行处理
这里有一个我自己的用于这种情况下解决引号转化的纯XSLT方法
<xsl:template name="captureQuot">
<xsl:param name="processText"/>
<xsl:call-template name="captureSingleQuot">
<xsl:with-param name="processText">
<xsl:call-template name="captureDoubleQuot">
<xsl:with-param name="processText" select="$processText" />
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="captureSingleQuot">
<xsl:param name="processText"/>
<xsl:choose>
<xsl:when test="contains($processText, "'")">
<xsl:value-of select="substring-before($processText,"'")" />
<xsl:text>\'</xsl:text>
<xsl:call-template name="captureSingleQuot">
<xsl:with-param name="processText" select="substring-after($processText,"'")"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$processText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="captureDoubleQuot">
<xsl:param name="processText"/>
<xsl:choose>
<xsl:when test="contains($processText, '"')">
<xsl:value-of select="substring-before($processText,'"')" />
<xsl:text>\"</xsl:text>
<xsl:call-template name="captureDoubleQuot">
<xsl:with-param name="processText" select="substring-after($processText,'"')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$processText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
如果你的SearchResult/Info/Key里面含有引号那么还要对引号进行处理
这里有一个我自己的用于这种情况下解决引号转化的纯XSLT方法
<xsl:template name="captureQuot">
<xsl:param name="processText"/>
<xsl:call-template name="captureSingleQuot">
<xsl:with-param name="processText">
<xsl:call-template name="captureDoubleQuot">
<xsl:with-param name="processText" select="$processText" />
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="captureSingleQuot">
<xsl:param name="processText"/>
<xsl:choose>
<xsl:when test="contains($processText, "'")">
<xsl:value-of select="substring-before($processText,"'")" />
<xsl:text>\'</xsl:text>
<xsl:call-template name="captureSingleQuot">
<xsl:with-param name="processText" select="substring-after($processText,"'")"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$processText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="captureDoubleQuot">
<xsl:param name="processText"/>
<xsl:choose>
<xsl:when test="contains($processText, '"')">
<xsl:value-of select="substring-before($processText,'"')" />
<xsl:text>\"</xsl:text>
<xsl:call-template name="captureDoubleQuot">
<xsl:with-param name="processText" select="substring-after($processText,'"')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$processText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
作者: silverdrag 发布时间: 2008-08-02
晕,代码被转换成html的输出了
晕,代码被转换成html的输出了
<xsl:template name="captureQuot">
<xsl:param name="processText"/>
<xsl:call-template name="captureSingleQuot">
<xsl:with-param name="processText">
<xsl:call-template name="captureDoubleQuot">
<xsl:with-param name="processText" select="$processText" />
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="captureSingleQuot">
<xsl:param name="processText"/>
<xsl:choose>
<xsl:when test="contains($processText, "'")">
<xsl:value-of select="substring-before($processText,"'")" />
<xsl:text>\'</xsl:text>
<xsl:call-template name="captureSingleQuot">
<xsl:with-param name="processText" select="substring-after($processText,"'")"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$processText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="captureDoubleQuot">
<xsl:param name="processText"/>
<xsl:choose>
<xsl:when test="contains($processText, '"')">
<xsl:value-of select="substring-before($processText,'"')" />
<xsl:text>\&quot;</xsl:text>
<xsl:call-template name="captureDoubleQuot">
<xsl:with-param name="processText" select="substring-after($processText,'"')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$processText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
[ 本帖最后由 silverdrag 于 2008-8-2 14:01 编辑 ]
晕,代码被转换成html的输出了
<xsl:template name="captureQuot">
<xsl:param name="processText"/>
<xsl:call-template name="captureSingleQuot">
<xsl:with-param name="processText">
<xsl:call-template name="captureDoubleQuot">
<xsl:with-param name="processText" select="$processText" />
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="captureSingleQuot">
<xsl:param name="processText"/>
<xsl:choose>
<xsl:when test="contains($processText, "'")">
<xsl:value-of select="substring-before($processText,"'")" />
<xsl:text>\'</xsl:text>
<xsl:call-template name="captureSingleQuot">
<xsl:with-param name="processText" select="substring-after($processText,"'")"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$processText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="captureDoubleQuot">
<xsl:param name="processText"/>
<xsl:choose>
<xsl:when test="contains($processText, '"')">
<xsl:value-of select="substring-before($processText,'"')" />
<xsl:text>\&quot;</xsl:text>
<xsl:call-template name="captureDoubleQuot">
<xsl:with-param name="processText" select="substring-after($processText,'"')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$processText"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
[ 本帖最后由 silverdrag 于 2008-8-2 14:01 编辑 ]
作者: silverdrag 发布时间: 2008-08-02
这里的\&quot;可呢功能比较不容易理解
其实&在这里的意思并不是最终输出的内容,它会被转换为&符号最终的输出实际上是\"
想必你应该已经想到最后的输出结果了
就是将单引号转化成\'
双引号转化成了\"
其实&在这里的意思并不是最终输出的内容,它会被转换为&符号最终的输出实际上是\"
想必你应该已经想到最后的输出结果了
就是将单引号转化成\'
双引号转化成了\"
作者: silverdrag 发布时间: 2008-08-02
最终结果就是
<input type="button" value="确定">
<xsl:attribute name="onclick">
changePage("<xsl:call-template name="captureQuot"><xsl:with-param name="processText" select="SearchResult/Info/Key')"/></xsl:call-template>");
<!--
也可以使用单引号
changePage('<xsl:call-template name="captureQuot"><xsl:with-param name="processText" select="SearchResult/Info/Key')"/></xsl:call-template>');
-->
</xsl:attribute>
</input>
<input type="button" value="确定">
<xsl:attribute name="onclick">
changePage("<xsl:call-template name="captureQuot"><xsl:with-param name="processText" select="SearchResult/Info/Key')"/></xsl:call-template>");
<!--
也可以使用单引号
changePage('<xsl:call-template name="captureQuot"><xsl:with-param name="processText" select="SearchResult/Info/Key')"/></xsl:call-template>');
-->
</xsl:attribute>
</input>
作者: silverdrag 发布时间: 2008-08-02
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28