首页 > 解决方案 > XSLT 无法将样式表附加到 XML

问题描述

Element root = document.createElement("urlset");
    document.setXmlStandalone(true);
    document.appendChild(root);
    root.setAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
    root.setAttribute("xmlns:xhtml", "http://www.w3.org/1999/xhtml");
    
    org.w3c.dom.ProcessingInstruction pi = document.createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"C:\\\\CanonWebApp\\\\utility\\\\sitemap.xslt encoding=\\\"utf-8\"");

      document.insertBefore((Node) pi, root);
      document.setXmlStandalone(true);

xml图片

我正在使用处理指令向我的 xml 添加样式表。我已将样式表保存在本地,但仍然出现如下屏幕截图所示的错误:

“此 XML 文件似乎没有与之关联的任何样式信息。文档树如下所示。”

标签: javaxmlxslt

解决方案


推荐阅读