显式脚本结束标记始终转换为自关闭 [英] Explicit script end tag always converted to self-closing

查看:26
本文介绍了显式脚本结束标记始终转换为自关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 xslt 将 xml 转换为 aspx 文件.在 xslt 中,我有一个脚本标记来包含 jquery.js 文件.为了让它与 IE 一起工作,脚本标签必须有一个明确的结束标签.出于某种原因,这不适用于下面的 xslt.

I'm using xslt to transform xml to an aspx file. In the xslt, I have a script tag to include a jquery.js file. To get it to work with IE, the script tag must have an explicit closing tag. For some reason, this doesn't work with xslt below.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    xmlns:asp="remove">    
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title>TEST</title>
                <script type="text/javascript" src="jquery-1.2.6.js"></script>

但是如果我如下所示更改脚本标签,它就可以工作.

But if I change the script tag as shown below, it works.

        <script type="text/javascript" src="jquery-1.2.6.js">
            // <![CDATA[ // ]]>
        </script>

我认为 <xsl:output method="html"/> 可以解决问题,但它似乎不起作用?

I thought that the <xsl:output method="html" /> would do the trick, but it doesn't seem to work?

/乔纳斯

推荐答案

如果您自己创建 XmlWriter,则需要将转换的 OutputSettings 传递给 XmlWriter,例如:

If you're creating the XmlWriter yourself you need to pass the transform's OutputSettings to the XmlWriter, eg:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<book><author>Trudi Canavan</author><title>Voice of the Gods</title></book>");

XslCompiledTransform transform = new XslCompiledTransform();
transform.Load("XSLTFile1.xslt");

StringBuilder output = new StringBuilder();

// Here we pass the output setting to the writer, otherwise the transform
// may be set to Html, but the XmlWriter will be outputting Xml
XmlWriter writer = XmlWriter.Create(output, transform.OutputSettings);

transform.Transform(doc, writer);

Console.WriteLine(output.ToString());
Console.ReadKey();

这篇关于显式脚本结束标记始终转换为自关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆