将xsl嵌入到XML文件中

时间:2021-11-07 15:40:59

I'm trying to embed an xsl into a XML file. The reason for doing this is to create a single file that could be moved to different computers, this would prevent the need to move the xsl file.

我正在尝试将xsl嵌入到XML文件中。这样做的原因是创建一个可以移动到不同计算机的单个文件,这将防止需要移动xsl文件。

The xsl file is creating a table and grabbing a test step from the xml and whether it passed or failed, pretty simple.
The issue I'm having, I think, is that the xsl has javascript and its being displayed when the xml is loaded in IE.

xsl文件正在创建一个表并从xml中获取测试步骤以及它是通过还是失败,非常简单。我认为,我遇到的问题是xsl有javascript,并且在IE中加载xml时会显示它。

When I load the xml file with IE, the javascript is displayed above the table and below the table the xml is displayed.

当我用IE加载xml文件时,javascript显示在表格上方,在表格下方显示xml。

Here is how my document is laid-out :

这是我的文件的布局:

<!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>

3 个解决方案

#1


11  

Although the W3C XSLT Spec supports embedding an XSLT stylesheet into an XML document, it seems that IE and Firefox do not support this.

尽管W3C XSLT规范支持将XSLT样式表嵌入到XML文档中,但似乎IE和Firefox不支持这一点。

UPDATE: As per the comment by Robert Niestroj, years later, in Oct. 2014, this works in FireFox 33.

更新:根据Robert Niestroj的评论,多年后,在2014年10月,这适用于FireFox 33。

However, there is a good alternative: embed the XML document into the XSLT stylesheet.

但是,有一个很好的选择:将XML文档嵌入到XSLT样式表中。

Below is an example.

以下是一个例子。

An XSLT stylesheet containing an embedded XML document:

包含嵌入式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>

When tis file is opened in IE, the wanted result is displayed by the browser:

在IE中打开tis文件时,浏览器会显示想要的结果:

Hello I am foo

Do note, that it is necessary to include templates that ignore most of the XSLT instructions (in this case we are ignoring any <xsl:template> by simply having no template body.

请注意,有必要包含忽略大多数XSLT指令的模板(在这种情况下,我们忽略任何 ,只是没有模板体。 :template>

#2


0  

Stylesheet embedding is possible for most browsers but IE. Find the reference to a description and example in the posting below.

除了IE之外,大多数浏览器都可以使用样式表嵌入。在下面的帖子中找到对描述和示例的引用。

IE6/7/8 do not support embedded stylesheets by default.

IE6 / 7/8默认情况下不支持嵌入式样式表。

You may want to use the workaround enabling IE to process embedded stylesheets from here:

您可能希望使用解决方法启用IE来处理嵌入式样式表:

http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201001/msg00390.html

http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201001/msg00390.html

#3


0  

Because your stylesheet makes use of msxsl the previous technique for anabling stylesheet embedding for IE browsers should be fine for you.

因为您的样式表使用了msxsl,所以为IE浏览器启用样式表嵌入的先前技术应该没问题。

If you want stylesheet embedding which works for all browsers you might want to use technique support of stylesheet embedding for ALL browsers.

如果您希望样式表嵌入适用于所有浏览器,您可能希望对所有浏览器使用样式表嵌入的技术支持。

#1


11  

Although the W3C XSLT Spec supports embedding an XSLT stylesheet into an XML document, it seems that IE and Firefox do not support this.

尽管W3C XSLT规范支持将XSLT样式表嵌入到XML文档中,但似乎IE和Firefox不支持这一点。

UPDATE: As per the comment by Robert Niestroj, years later, in Oct. 2014, this works in FireFox 33.

更新:根据Robert Niestroj的评论,多年后,在2014年10月,这适用于FireFox 33。

However, there is a good alternative: embed the XML document into the XSLT stylesheet.

但是,有一个很好的选择:将XML文档嵌入到XSLT样式表中。

Below is an example.

以下是一个例子。

An XSLT stylesheet containing an embedded XML document:

包含嵌入式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>

When tis file is opened in IE, the wanted result is displayed by the browser:

在IE中打开tis文件时,浏览器会显示想要的结果:

Hello I am foo

Do note, that it is necessary to include templates that ignore most of the XSLT instructions (in this case we are ignoring any <xsl:template> by simply having no template body.

请注意,有必要包含忽略大多数XSLT指令的模板(在这种情况下,我们忽略任何 ,只是没有模板体。 :template>

#2


0  

Stylesheet embedding is possible for most browsers but IE. Find the reference to a description and example in the posting below.

除了IE之外,大多数浏览器都可以使用样式表嵌入。在下面的帖子中找到对描述和示例的引用。

IE6/7/8 do not support embedded stylesheets by default.

IE6 / 7/8默认情况下不支持嵌入式样式表。

You may want to use the workaround enabling IE to process embedded stylesheets from here:

您可能希望使用解决方法启用IE来处理嵌入式样式表:

http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201001/msg00390.html

http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/201001/msg00390.html

#3


0  

Because your stylesheet makes use of msxsl the previous technique for anabling stylesheet embedding for IE browsers should be fine for you.

因为您的样式表使用了msxsl,所以为IE浏览器启用样式表嵌入的先前技术应该没问题。

If you want stylesheet embedding which works for all browsers you might want to use technique support of stylesheet embedding for ALL browsers.

如果您希望样式表嵌入适用于所有浏览器,您可能希望对所有浏览器使用样式表嵌入的技术支持。