+ -
当前位置:首页 → 问答吧 → 关于XSL与JS通信的问题

关于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]]

作者: xjfseasky   发布时间: 2008-06-12

解决.
这里只能使用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>

作者: 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, &quot;'&quot;)">
                                <xsl:value-of select="substring-before($processText,&quot;'&quot;)" />
                                <xsl:text>\'</xsl:text>
                                <xsl:call-template name="captureSingleQuot">
                                        <xsl:with-param name="processText" select="substring-after($processText,&quot;'&quot;)"/>
                                </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, '&quot;')">
                                <xsl:value-of select="substring-before($processText,'&quot;')" />
                                <xsl:text>\&amp;quot;</xsl:text>
                                <xsl:call-template name="captureDoubleQuot">
                                        <xsl:with-param name="processText" select="substring-after($processText,'&quot;')"/>
                                </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

这里的\&amp;quot;可呢功能比较不容易理解
其实&amp;在这里的意思并不是最终输出的内容,它会被转换为&符号最终的输出实际上是\&quot;
想必你应该已经想到最后的输出结果了
就是将单引号转化成\'
双引号转化成了\&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>

作者: silverdrag   发布时间: 2008-08-02

热门下载

更多