以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DOM/SAX/XPath 』  (http://bbs.xml.org.cn/list.asp?boardid=11)
----  xml或xsl中能嵌入javascript吗?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=11&rootid=&id=23459)


--  作者:师父2005
--  发布时间:10/23/2005 12:23:00 AM

--  xml或xsl中能嵌入javascript吗?
xml或xsl中能嵌入javascript吗?
--  作者:anchen0617
--  发布时间:10/23/2005 12:38:00 AM

--  
我想应该可以的。但我没有试过。
--  作者:师父2005
--  发布时间:10/23/2005 12:50:00 PM

--  继续关注~~~~~
首先非常感谢楼上的能回帖.
xsl中加入javascript我试过,不会报错,但是它以下的部分不起作用.
xml就没试过了.我的问题其实主要是在以下链接里:http://bbs.xml.org.cn/dispbbs.asp?boardID=8&ID=23458 望大家看一下
--  作者:JavaXML
--  发布时间:10/26/2005 12:02:00 PM

--  
在XSL中可以,XML中没试过
--  作者:师父2005
--  发布时间:10/27/2005 4:39:00 PM

--  
那么知道如何在js读出xml中元素后追加节点,然后调用xsl显示吗?好像调用appendchildnodes可以实现,但是具体的实现代码找了好久都没找到。谁知道代码,粘贴一下让小弟看看,可以吗?
--  作者:white.gourd
--  发布时间:11/10/2005 10:08:00 PM

--  
RE: [xsl] VBScript in XSLT

Yes.

You can include javascript or VBscript in your html output.

Just include it as you want it to be displayed as,

ie.
<script>
function openWindow(url){
  newWindow = window.open(url, 'newWindow',
'menubar=no,location=no,scrollbars=yes,status=no,resizable=yes,width=640,hei
ght=480,alwaysRaised')
  newWindow.focus()
}
</script>

But ensure that you escape charactors which would cause problems - ie use
&gt; rather than '>'

ie.
<script>
If xyz &gt; 1 ...
</script>

rather than

<script>
If xyz > 1 ...
</script>

You can also use <xsl:text disable-output-escaping="yes"><![CDATA[ "your
code in here"  ]]></xsl:text> if you have a lot of charactors and don't want
to escape them all

hope that helps,

比较懒,直接粘过来了


--  作者:white.gourd
--  发布时间:11/10/2005 10:12:00 PM

--  
<xsl:script
   language = "language-name"
   implements-prefix = "prefix of user's namespace">
<![CDATA[
script language code
]]>
</msxsl:script>
--  作者:white.gourd
--  发布时间:11/10/2005 10:14:00 PM

--  
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:user="http://mycompany.com/mynamespace">

  <msxsl:script language="VBScript" implements-prefix="user">
    <![CDATA[
    ' Input: A currency value - the wholesale price
    ' Returns: the retail price - the inputted value plus a 20% margin,
    ' rounded to the nearest cent.
    Function AddMargin(WholesalePrice)
      AddMargin = round(WholesalePrice * 1.2, 2)
    End Function
  ]]>
  </msxsl:script>

  <xsl:template match="/">
    <html>
      <body>
        <xsl:for-each select="books/book">
          <p>
            <xsl:value-of select="position()"/>.
            <xsl:value-of select="name"/>
                   Retail $<xsl:value-of select="user:AddMargin(number(price))"/>
                   Wholesale $<xsl:value-of select="number(price)"/>
          </p>
        </xsl:for-each>
        <p>
          <b>Total Retail Price =
            $<xsl:value-of select="user:AddMargin(sum(//price))"/>
          </b><br/>
          <b>Total Wholesale Price =
            $<xsl:value-of select="sum(//price)"/>
          </b>
        </p>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>


--  作者:yishui
--  发布时间:11/12/2005 4:58:00 PM

--  
bu cuo
--  作者:jellifier
--  发布时间:12/28/2005 10:26:00 AM

--  
<xsl:value-of select="name"/>
                   Retail $<xsl:value-of select="user:AddMargin(number(price))"/>
                   Wholesale $<xsl:value-of select="number(price)"/>
这一段是什么意思啊,如果用javascript应该怎么写呢
--  作者:xiongbajian
--  发布时间:12/28/2005 6:55:00 PM

--  
我刚发现xsl中加入外部javascript的方法和在html中的方法一样。
--  作者:bruceshen
--  发布时间:6/16/2006 9:58:00 AM

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