XSLT文件是否在XML文件中呈现动态更改

时间:2013-09-02 13:49:08

标签: xml xslt

我是XSLT域的新手,我有一个html文件通过XSLT呈现XML文件的内容。在XML中进行一些动态更改后,XSLT的行为根据动态更改是XML和 html页面渲染动态内容或者是否需要重新打开引用该xml的html文件。

我的XMl文件就像

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="XSL.xsl"?>
<Arithmetic>
    <Function>
        <FunctionName>-</FunctionName>
    </Function>
    <Function>
        <FunctionName>/</FunctionName>
    </Function>
    <Function>
        <FunctionName>*</FunctionName>
    </Function>
    <Function>
        <FunctionName>MOD</FunctionName>
    </Function>
    <Function>
        <FunctionName>^</FunctionName>
    </Function>
   </Arithmetic>

我的XSLT文件是

**<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/*">
  <html>
  <body>
  <table border="1">
    <tr bgcolor="#9acd32">
      <th>Title</th>

    </tr>
    <xsl:for-each select="/*/Function">
    <tr>
      <td><xsl:value-of select="FunctionName"/></td>

    </tr>
    </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>** 

我的示例html就像

<html>
<head>
<SCRIPT LANGUAGE=javascript>

 function createDom(stringXML){
        var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); // create a xmlDOM object
         xmlDoc.async="false"
         xmlDoc.loadXML(stringXML);
return xmlDoc;
} 
function onOk()
{
    xmlDom2 = createDom("<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="XSL.xsl"?><Geometric><Function><FunctionName>-</FunctionName></Function><Function><FunctionName>/</FunctionName></Function><Function><FunctionName>*</FunctionName></Function><Function><FunctionName>MOD</FunctionName></Function><Function><FunctionName>^</FunctionName></Function></Geometric>");
    //now how could i give ref of that updated xml in the iframe or how the iframe will render this update xml 
}
</SCRIPT >

</head>
<body >
    <div id = "mainDiv" class = "scrollbar" style = "border:1px inset;height: 186px; overflow: auto;">

        <IFRAME src = "XML.xml" id="IFRAME" style="visibility: visible;" ></IFRAME> 
        <INPUT id=btnOk onclick=onOk() type=button size=35 value=Change XML >

    </div>
</body>
</html>

感谢

3 个答案:

答案 0 :(得分:3)

您可能希望看看Saxon-CE这种应用。 Saxon-CE在浏览器中运行XSLT 2.0,允许您编写响应特定事件的模板规则。如果XML在服务器上,那么当然它不会自动注意到服务器端XML已经改变,但是您可以安排与服务器上的应用程序通信以获得此类事件的通知。

答案 1 :(得分:0)

html中的渲染将取决于xml和xslt标记。如果未在xslt中定义xml中的更改,则渲染将不会在html中发生。

答案 2 :(得分:0)

如果在浏览器中打开XML后编辑XML,则需要再次运行XSLT转换过程。

您在浏览器中看到的HTML是渲染过程的结果,该过程不是动态运行的。我想您可以观察XML以进行更改并重建HTML文件,但这将是一种命令行方法。