誰能告訴我爲什麼下面的XSL在IE9中愉快地轉換下面的XML,但是在所有版本的Visual Studio下,相同的轉換都失敗了?如果我在IE 9中打開XML文件,它會被轉換並且輸出如預期的那樣,但是如果我在Visual Studio中對XML文件進行相同的轉換(使用工具欄上的「啓動XSLT」按鈕),我會得到一個JScriptException話說功能有望上線Visual Studio和IE之間行爲的XSL/JScript差異
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>
謝謝 - 我想你已經找到了答案。我不打算爲兩者開發,我想這只是一個工作流程問題 - 我在部署在IE上之前在Visual Studio中進行了調試,所以這給我帶來了一些麻煩。 – 2011-05-23 11:33:42