我正在尝试将 xsl 嵌入到 XML 文件中。这样做的原因是创建一个可以移动到不同计算机的单个文件,这将避免移动 xsl 文件的需要。
xsl文件就是创建一个表,从xml中抓取一个测试步骤,判断通过还是失败,很简单。
我认为我遇到的问题是 xsl 有 javascript 并且在 IE 中加载 xml 时显示它。
当我用 IE 加载 xml 文件时,javascript 显示在表格上方,表格下方显示 xml。
这是我的文档布局方式:
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
id ID #REQUIRED>
]>
<doc>
<xsl:stylesheet id="4.1.0"
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://www.ni.com/TestStand"
xmlns:vb_user="http://www.ni.com/TestStand/" >
<xsl:template match="xsl:stylesheet" />
<xsl:text disable-output-escaping="yes">
<msxsl:script language="vbscript" implements-prefix="vb_user">
option explicit
'This function will return the localized decimal point for a decimal number
Function GetLocalizedDecimalPoint ()
dim lDecPoint
lDecPoint = Mid(CStr(1.1),2,1)
GetLocalizedDecimalPoint = lDecPoint
End Function
</msxsl:script>
<msxsl:script language="javascript" implements-prefix="user"><![CDATA[
// This style sheet will not show tables instead of graphs for arrays of values if
// 1. TSGraph control is not installed on the machine
// 2. Using the stylesheet in windows XP SP2. Security settings prevent stylesheets from creatign the GraphControl using scripting.
// Refer to the TestStand Readme for more information.
//more javascript functions
//code to build table and insert data from the xml
</xsl:stylesheet>
<Reports>
<Report Type='UUT' Title='UUT Report' Link='-1-2008-12-3-10-46-52-713' UUTResult='Failed' StepCount='51'>
// rest of xml
</Report>
</Reports>
</doc>
最佳答案
Although the W3C XSLT Spec supports embedding an XSLT stylesheet成XML文件,IE和Firefox好像不支持。
更新:根据 Robert Niestroj 的评论,多年后的 2014 年 10 月,这在 FireFox 33 中有效。
但是,有一个很好的选择:将 XML 文档嵌入到 XSLT 样式表中。
下面是一个例子。
包含嵌入式 XML 文档的 XSLT 样式表:
<?xml-stylesheet type="text/xsl" href="myEmbedded.xml"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:variable name="vEmbDoc"> <doc> <head></head> <body> <para id="foo">Hello I am foo</para> </body> </doc> </xsl:variable> <xsl:template match="para"> <h1><xsl:value-of select="."/></h1> </xsl:template> <xsl:template match="xsl:template"/> </xsl:stylesheet>
在IE中打开这个文件,浏览器显示想要的结果:
你好我是foo
请注意,有必要包括忽略大部分 XSLT 指令的模板(在这种情况下,我们忽略任何 <xsl:template>
,因为没有模板主体。
关于javascript - 将 xsl 嵌入到 XML 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/360628/