急求msxsl:script元素的使用方法和例子

volcanodeng 2004-04-29 06:38:17
使用微软的xslt元素msxsl:script时老是出现错误,本人编写的程序:
<msxsl:script language="javascript" implements-prefix="urn:schemas-microsoft-com:xslt">window.alert('natify');</msxsl:script>
但该程序无法在msxml2.xsltemplate对象中执行转换,请高手指教!!
...全文
101 31 打赏 收藏 转发到动态 举报
写回复
用AI写文章
31 条回复
切换为时间正序
请发表友善的回复…
发表回复
volcanodeng 2004-05-12
  • 打赏
  • 举报
回复
Thanks for all replies!
OK,the problem has been resolved!
Let me pay for the scores!
胖河马 2004-05-09
  • 打赏
  • 举报
回复
TestSample.xsl改成
……
<xsl:for-each select="data/value">
<xsl:if test="position()=last()">
setVariable(<xsl:value-of select="@id"/>);
</xsl:if>
</xsl:for-each>
……

TransformFile.htm改成

……
function initialFun() {
……
pro.transform();
window.execScript(pro.output);
}
……
gjd111686 2004-05-09
  • 打赏
  • 举报
回复
第一次看到第一高手,学习.
saucer 2004-05-08
  • 打赏
  • 举报
回复
maybe there is some misunderstanding here, give some code example, we will show you a way
胖河马 2004-05-08
  • 打赏
  • 举报
回复
还可以将数据节点转化成数据岛
胖河马 2004-05-08
  • 打赏
  • 举报
回复
隐藏文本框的id也是可以通过xsl生成
volcanodeng 2004-05-08
  • 打赏
  • 举报
回复
Right! But how?
saucer 2004-05-08
  • 打赏
  • 举报
回复
try

<xsl:if test="position()=last()">
 <script language="javascript" defer="true">setVariable(<xsl:value-of select="@id"/>);</script>
</xsl:if>

there seems to be a bug, you need to output some text , or try

<xsl:if test="position()=last()">
 <xsl:element name="script">
<xsl:attribute name="language">javascript</xsl:attribute>
<xsl:attribute name="defer">true</xsl:attribute>
setVariable(<xsl:value-of select="@id"/>);
</xsl:element>
</xsl:if>
saucer 2004-05-08
  • 打赏
  • 举报
回复
why do you need an event handler? you can just call the method
volcanodeng 2004-05-08
  • 打赏
  • 举报
回复
Yes, saucer(思归/MVP).But the page that I use xsl transform is a no refreshing page,so it is difficult to reload the window.onload event handle.I do all data exchange by xmlhttp,and I do not need to refresh the page.

Can you get a solution that execute the event handler automatically?
volcanodeng 2004-05-08
  • 打赏
  • 举报
回复
bdhh(Silent),您提供的方法并不十分可行。

因为,每个隐藏文本框都带唯一id,当我们要获取其中的值时必须要知道明确的文本框id,但xsl无法捕获这些id,如果xsl能记录这些id的话,我们也就无需再用隐藏文本框了,我们可以直接保存值到记录变量中,所以这种方法不十分可行。
saucer 2004-05-08
  • 打赏
  • 举报
回复
if I understand you correctly, write a window.onload event handler
volcanodeng 2004-05-08
  • 打赏
  • 举报
回复
Oh,Yes!Thanks for saucer(思归/MVP)'s great help!

I think your sample code has illuminate everything that puzzle me some days.Thank you very much again.

By the way,may I ask you another question? Your sample code has soled the transform and evaluate problem indeed, but the javascript function still depend on the element event,and the evaluate statement only execute by custom event.So how can I make it executing immediately all javascript code of the transformer itself ?
volcanodeng 2004-05-08
  • 打赏
  • 举报
回复
1.TestSample.xml
<?xml version="1.0"?>
<data>
<value id="1">hello</value>
<value id="2">csdn</value>
<value id="3">world</value>
</data>

2.TestSample.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="data/value">
<xsl:if test="position()=last()">
<script language="javascript">setVariable(<xsl:value-of select="@id"/>);</script>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

3.TransformFile.htm
<html>
<head>
<script language="javascript">
function setVariable(valueid)
{
gVar=valueid;
window.alert(gVar);
}

function initialFun()
{
var xdoc=new ActiveXObject("msxml2.domdocument");
xdoc.async=false;
xdoc.load("TestSample.xml");
var doc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
doc.async=false;
doc.load("TestSample.xsl");

var xsltem=new ActiveXObject("Msxml2.XSLTemplate");
xsltem.stylesheet=doc;

var pro=xsltem.createProcessor();
pro.input=xdoc;
pro.transform();

document.all("codecontainer").innerHTML=pro.output;
}
</script>
</head>
<body onload="initialFun()">
<div id="codecontainer"></div>
</body>
</html>



My question:How can I execute the function setVariable dynamically?
胖河马 2004-05-07
  • 打赏
  • 举报
回复
你可以将值转换到隐藏文本框中
saucer 2004-05-06
  • 打赏
  • 举报
回复
1. TestScript.xml

<?xml-stylesheet type="text/xsl" href="TestScript.xsl" ?>
<data>
<value>hello</value>
<value>csdn</value>
<value>world</value>
</data>

2. TestScript.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
<html>
<head>
<script language="javascript">
var val;
var n = 1;

function transform()
{
var xmldom = document.XMLDocument;
var xsldom = document.XSLDocument;
var xmlnode = xmldom.documentElement;
var xslnode = xsldom.selectSingleNode("//xsl:param[@name='n']");
n++;
xslnode.setAttribute("select",n);

mydiv.innerHTML = xmlnode.transformNode(xsldom);

alert(mydiv.innerHTML);
}
</script>
</head>
<body>
<div id="mydiv">
<xsl:apply-templates />
</div>
<input type="button" value="transform Next" onclick="transform()" />
<input type="button" value="get value" onclick="alert(val);" />
</body>
</html>
</xsl:template>

<xsl:template match="data">
<xsl:param name="n" select="1" />
proof of concept--- value is: <xsl:value-of select='value[position()=$n]' />
<script language="javascript" defer="true">
val = "<xsl:value-of select='value[position()=$n]' />";
</script>
</xsl:template>

</xsl:stylesheet>
胖河马 2004-05-06
  • 打赏
  • 举报
回复
xsl是用来讲一个xml转换成另外一个xml的。所以它无法与目标文档交互是正常的,它根本不会识别dom。
另外,浏览器的解析过程是将xml转换成xhtml然后才生成dom,也就是说转换过程中dom还没有形成。
而且它没有界面交互能力,所以不能调用alert。
saucer 2004-05-06
  • 打赏
  • 举报
回复
you'd better create a simple xml/xsl sample, tell us exactly what you want

<script language="javascript">
val = "<xsl:value-of select='....' />";
</script>
volcanodeng 2004-05-06
  • 打赏
  • 举报
回复
谢谢bdhh(Silent),您所提到的问题很有道理。

本人想解决的是一个传值的问题:用xsl转换xml后怎样将原来xml中特定的数据写入生成的HTML文件页里的javascript变量中?

若我只用一个xsl模板,每次更换xml,并保持对xml进行转换操作的javascript脚本不刷新,则怎样转换特定的xml数据到javascript变量中,而不是直接转换成静态HTML?
volcanodeng 2004-05-06
  • 打赏
  • 举报
回复
Thanks for saucer(思归/MVP),and thanks for your commendatory site.I think you are right.The value saved in the global variable may be evaluated again or lost its original value.

But,what I want to resolve is that how can I get a value from the xsl transforming process,why I refer to the <msxsl:script> element is I want to use the javascript in xsl to interact with the javascript in HTML.I need a dynamic data exchange.Now the xsltemplate only give me the <xsl:param> to input values,but it can not give me a way to output values as dynamically interact usage,which just like a javascript variable.

加载更多回复(11)
源码8 IDOMDocument vs. IXMLDocument.... . 8 TXMLDocument Programming .... 9 XML TreeView .. 12 TXMLDocument as Windows Service........................................... 14 XML Data Binding .............................................................................. 16 Generated Code ...................................................................... 20 Delphi XML Mapper............................................................................ 23 The XML Mapping Tool.............................................................. 23 Selecting Nodes ...................................................................... 24 Create and Test Transformation................................................. 26 XMLTransform......................................................................... 28 Visual Transformation .............................................................. 30 TXMLTransformClient ............................................................... 31 XSLT ............................................................................................... 32 XSL Transformations................................................................ 32 MSXSL ................................................................................... 32 Some examples of XSLT.................................................... 32 Default XSLT Templates ........................................................... 34 Our own XSLT Processor........................................................... 35 XML and XSL .......................................................................... 35 XMLData property ............................................................ 35 FileName property............................................................ 35 XML property................................................................... 36 XSLT Processor ....................................................................... 37 Alternative Approach ........................................................ 37 Summary......................................................................................... 38 2. Web Services: SOAP & WSDL 39 Web Services.................................................................................... 39 SOAP..................................................................................... 39 WSDL .................................................................................... 39 XSD Data Types ...................................................................... 41 SOAP and XML ........................................................................ 41 Building Delphi for Win32 Web Services................................................ 42 Debug and ISAPI..................................................................... 43 Second target (Indy) ........................................................ 44 SOAP Web Module............................................................ 45 SOAP Server Interface ............................................................. 47 SOAP Server Implementation .................................................... 51 Indy VCL Project ............................................................................... 53 Consuming Web Services.................................................................... 55 SOAP Client ............................................................................ 56 Using GetIEcho ....................................................................... 60 Delphi XML, SOAP & Web Services Bob Swart Training & Consultancy - iii - www.drbob42.com Using THTTPRIO...................................................................... 64 WSDL vs. SOAP....................................................................... 65 AdminEnabled......................................................................... 66 GetIEcho Implementation ......................................................... 69 Conversion Web Services.................................................................... 70 TemperatureIntf...................................................................... 72 TemperatureImpl .................................................................... 72 Debugging Web Services .................................................................... 73 Web Service Client................................................................... 73 Server Breakpoints .................................................................. 74 Deployment on Windows Server 2003 and IIS ....................................... 75 Enabling ISAPI / CGI................................................................ 75 Virtual Directory ...................................................................... 76 SSL Certificates................................................................................. 79 SSL and IIS6 on Windows Server 2003....................................... 79 Installing SSL Certificates ......................................................... 82 Deployment on Windows Server 2008 and IIS7 ........................... 83 Tracing Web Services......................................................................... 88 SOAP and Exceptions ......................................................................... 89 Echo Interface unit .................................................................. 89 Echo implementation unit ......................................................... 89 Echo import unit...................................................................... 90 Extending SOAP Exceptions....................................................... 90 SOAP and Databases ......................................................................... 92 Database Client....................................................................... 94 Extra Data Module ................................................................... 96 Alternative to data module: web module..................................... 98 SOAP Attachments ............................................................................ 98 Receiving SOAP Attachments .................................................... 101 Summary......................................................................................... 103 Exercises.......................................................................................... 103 Exercise #1 ............................................................................ 103 Exercise #2 ............................................................................ 103 Exercise #3 ............................................................................ 103 Exercise #4 ............................................................................ 103 Exercise #5 ............................................................................ 103 Exercise #6 ............................................................................ 103 Exercise #7 ............................................................................ 103 Exercise #8 ............................................................................ 103 3. SOAP and Security 105 SSL Certificates................................................................................. 105 Web Service Example......................................................................... 105 SourceCodeIntf................................................................ 105 SourceCodeImpl .............................................................. 106 Importing Win32 Secure Web Service ................................. 107 Summary......................................................................................... 108 Exercises.......................................................................................... 108 Exercise #1 ............................................................................ 108 Exercise #2 ............................................................................ 108 Exercise #3 ............................................................................ 108 4. Case Study: Automatic Updates 109

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧