Embed xsl into an XML file

后端 未结 3 629
慢半拍i
慢半拍i 2020-12-19 09:14

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

相关标签:
3条回答
  • 2020-12-19 09:35

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

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

    0 讨论(0)
  • 2020-12-19 09:46

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

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

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

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

    0 讨论(0)
  • 2020-12-19 09:49

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

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

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

    Below is an example.

    An XSLT stylesheet containing an embedded XML document:

    <?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:

    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.

    0 讨论(0)
提交回复
热议问题