以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  偶是新鸟~呵呵,初学~问一个问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=38326)


--  作者:Leixian
--  发布时间:9/26/2006 7:27:00 PM

--  偶是新鸟~呵呵,初学~问一个问题
怎样在XSL中用JS??
比如在XML中有个元素GetCity值为00000
<GetCity>00000</GetCity>

那么我怎样才能在XSL中用JS函数调用这个值呢??
就像 <script language="JavaScript">getCity("str");</script>
这样调用,用XSL怎么实现?~


--  作者:Qr
--  发布时间:9/27/2006 12:16:00 PM

--  
自己随意写的,参考一下吧
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="text/xsl" href="alert1.xsl" ?>
<root>
  <books>
    <bookID>001</bookID>
    <bookName>XML</bookName>
  </books>
  <books>
    <bookID>002</bookID>
    <bookName>XSL</bookName>
  </books>
</root>


<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head>
<script>
function getDetail(x)
{
alert(x);
}
</script>

</head>
<body>
<xsl:apply-templates select="root/books" />
</body>
</html>
</xsl:template>

<xsl:template match="books">
<DIV>
<xsl:attribute name="onClick">getDetail('<xsl:value-of

select="bookID"/>')</xsl:attribute>
<xsl:value-of select="bookName"/>
</DIV>
</xsl:template>
</xsl:stylesheet>


--  作者:Leixian
--  发布时间:9/27/2006 5:48:00 PM

--  
呵呵,谢谢!
不过我做的是需要函数返回一个值,并在函数调用的位置显示
那么这个时候应该怎么做呢?我把onClick改为innerHTML也不行啊~


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
31.250ms