2017-09-02 116 views
0

我已經嘗試了許多方法來訪問XSL變量的JavaScript這裏是我的代碼,請幫我找到解決辦法如何訪問在JavaScript

<xsl:variable name="VariableName"> 
<xsl:for-each select="ROW/COL/LIST-BOX/DATA"> 
    <xsl:choose> 
     <xsl:when test="position() =1"> 
      <xsl:value-of select="."/> 
     </xsl:when> 
     <xsl:otherwise> 
      |<xsl:value-of select="."/> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:for-each> 
</xsl:variable> 
<body> 
<xsl:attribute name='onLoad'>javaScript:userDetails()</xsl:attribute> 
<script type="text/javascript" language="javascript"> 
function userDetails() 
{ 
var title = <xsl:value-of select="$VariableName"/>; 
alert(title); 
} 
</script> 
</body> 

回答

0
Check following code 

<xsl:variable name="VariableName"> 
<xsl:for-each select="ROW/COL/LIST-BOX/DATA"> 
    <xsl:choose> 
    <xsl:when test="position() =1"> 
     <xsl:value-of select="."/> 
    </xsl:when> 
    <xsl:otherwise> 
     |<xsl:value-of select="."/> 
    </xsl:otherwise> 
</xsl:choose> 
</xsl:for-each> 
</xsl:variable> 

<body onload="userDetails()"> 
<script type="text/javascript" language="javascript"> 
    function userDetails() 
     { 
      var title = "<xsl:value-of select="$VariableName"/>" 
      alert(title); 
     } 
</script> 
</body> 
+0

.... – user3315903

0

莫名其妙地發現XSL變量.. 。
XSL

<table> 
    <tr><td id="Rtest"><xsl:value-of select="$VariableName" /></td></tr> 
</table> 

JS

var myString= document.getElementById("Rtest").innerHTML; 

現在,它正在莫名其妙地發現