Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XSLT,需要将javascript插入onclick处理程序_Javascript_Xslt - Fatal编程技术网

XSLT,需要将javascript插入onclick处理程序

XSLT,需要将javascript插入onclick处理程序,javascript,xslt,Javascript,Xslt,我尝试了很多不同的方法。下面(不起作用)基本上就是我想做的。使用变量“defineClick”定义“onclick”代码,并将其动态插入div/onclick处理程序。$block变量在文件中定义为elsewere。谢谢 <xsl:choose> <xsl:when test="txtBlockTarget='_blank'"> <xsl:variable name="def

我尝试了很多不同的方法。下面(不起作用)基本上就是我想做的。使用变量“defineClick”定义“onclick”代码,并将其动态插入div/onclick处理程序。$block变量在文件中定义为elsewere。谢谢

          <xsl:choose>
                <xsl:when test="txtBlockTarget='_blank'">
                    <xsl:variable name="defineClick">window.open('{$block}','_blank');</xsl:variable>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:variable name="defineClick">location.href='{$block}';</xsl:variable>
                </xsl:otherwise>
            </xsl:choose>


            <div onclick="{$defineClick}" style="cursor: pointer;">

            .....more xsl.....

            </div>

window.open(“{$block}”,即“blank”);
location.href='{$block}';
…更多xsl。。。。。

xsl:when
中定义的变量的作用域为其父变量,在其父变量之外将不可用

尝试将您的操作顺序颠倒为:

<xsl:variable name="defineClick">
    <xsl:choose>
        <xsl:when test="txtBlockTarget='_blank'">window.open('{$block}','_blank');</xsl:when>
        <xsl:otherwise>location.href='{$block}';</xsl:otherwise>
    </xsl:choose>
</xsl:variable>

<div onclick="{$defineClick}" style="cursor: pointer;">
    ....more xsl.....
</div>

window.open(“{$block}”,即“blank”);
location.href='{$block}';
..更多xsl。。。。。


注意:我不确定您在使用变量编写
{$block}
时的意图;就目前而言,它不过是一根毫无意义的弦。但这将是另一个问题的主题。

xsl:when
中定义的变量的作用域为其父变量,在其父变量之外将不可用

尝试将您的操作顺序颠倒为:

<xsl:variable name="defineClick">
    <xsl:choose>
        <xsl:when test="txtBlockTarget='_blank'">window.open('{$block}','_blank');</xsl:when>
        <xsl:otherwise>location.href='{$block}';</xsl:otherwise>
    </xsl:choose>
</xsl:variable>

<div onclick="{$defineClick}" style="cursor: pointer;">
    ....more xsl.....
</div>

window.open(“{$block}”,即“blank”);
location.href='{$block}';
..更多xsl。。。。。


注意:我不确定您在使用变量编写
{$block}
时的意图;就目前而言,它不过是一根毫无意义的弦。但这将是一个单独的问题。

谢谢迈克尔!有时候,答案比看上去简单得多(以及到达那里的痛苦)。下面的代码可以工作

<xsl:variable name="defineClick">
    <xsl:choose>
       <xsl:when test="txtBlockTarget='_blank'">window.open('<xsl:value-of select="$block" />');</xsl:when>
       <xsl:otherwise>location.href='<xsl:value-of select="$block" />'</xsl:otherwise>
    </xsl:choose>
</xsl:variable>

<div onclick="{$defineClick}" style="cursor: pointer;">
......

窗口。打开(“”);
location.href=''
......

谢谢Michael!有时候,答案比看上去简单得多(以及到达那里的痛苦)。下面的代码可以工作

<xsl:variable name="defineClick">
    <xsl:choose>
       <xsl:when test="txtBlockTarget='_blank'">window.open('<xsl:value-of select="$block" />');</xsl:when>
       <xsl:otherwise>location.href='<xsl:value-of select="$block" />'</xsl:otherwise>
    </xsl:choose>
</xsl:variable>

<div onclick="{$defineClick}" style="cursor: pointer;">
......

窗口。打开(“”);
location.href=''
......

它的什么“不起作用”?它的什么“不起作用”?它是代码中其他地方起作用的变量,我只是不知道如何让它在嵌入javascript时加载值。有没有办法“逃离”它?感谢您修复了有关反转顺序的问题,我现在可以获得“defineClick”变量。请尝试使用
插入变量的内容。如果看不到整个画面,就很难说得更具体。如果您仍然无法让它工作,请发布一个新问题(如果回答了,请关闭此问题)。这是一个在代码中其他地方工作的变量,我只是不知道如何让它在嵌入javascript时加载值。有没有办法“逃离”它?感谢您修复了有关反转顺序的问题,我现在可以获得“defineClick”变量。请尝试使用
插入变量的内容。如果看不到整个画面,就很难说得更具体。如果你仍然无法让它工作,发布一个新的问题(如果有答案,关闭这个问题)。