【发布时间】:2011-05-23 10:01:00
【问题描述】:
谁能告诉我为什么下面的 XSL 在 IE9 中可以愉快地转换下面的 XML,但是在所有版本的 Visual Studio 下相同的转换都失败了?如果我在 IE 9 中打开 XML 文件,它会被转换并且输出符合预期,但是如果我尝试在 Visual Studio 中对 XML 文件进行相同的转换(使用工具栏上的“开始 XSLT”按钮),我会得到一个 JScriptException说功能就行了
var node = root.nextNode();
修复似乎是更改 javascript 函数以执行以下操作:
function test(root, attr)
{
root.MoveNext();
var node = root.Current;
return node.Select("breakfast" + attr);
}
但这会导致 IE 中的 XSLT 转换失败!我好像赢不了!
XSL:
<!--<?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="urn:custom-scripts">
<msxsl:script language="JScript" implements-prefix="user">
<![CDATA[
function test(root, attr)
{
var node = root.nextNode();
return node.selectSingleNode("breakfast" + attr);
}
]]>
</msxsl:script>
<xsl:template match="/">
<HTML>
<BODY STYLE="font-family:Arial, helvetica, sans-serif; font-size:12pt;
background-color:#EEEEEE">
<xsl:value-of select="user:test(., '-menu')"/>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
目标 XML:
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="simple.xsl" ?>
<breakfast-menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles
with plenty of real maple syrup.</description>
<calories>650</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast,
and our ever-popular hash browns.</description>
<calories>950</calories>
</food>
</breakfast-menu>
【问题讨论】:
标签: javascript xml internet-explorer xslt