为什么xmlLinq属性会杀死XSL转换?

时间:2015-10-01 19:57:44

标签: xml xslt

我有一个XSLT迭代这个XML并从“InterestingData”节点中选择元素。

由于“DontNeed2”节点中的此属性,转换失败:xmlns:xmlLinq="clr-namespace:System.Xml.Linq;assembly=System.Xml"

因此,如果我完全删除该属性,则转换成功。但是,我不控制该XML的生成,因此我需要能够处理它。 如果XSL甚至没有选择的节点中的这个属性如何能够终止转换,我该如何解决这个问题呢?

SomeTech.xml

<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns="">
  <DontNeed1>
    <Item name="one" />
    <Item name="two" />
    <Item name="three" />
  </DontNeed1>
  <DontNeed2>
    <transporters:SomeWebServiceTransportActivity xmlns:transporters="clr-namespace:SomeTech.DataFeed.Activities.Transporters;assembly=SomeTech.DataFeed" xmlns:out="clr-namespace:SomeTech.DataFeed;assembly=SomeTech.DataFeed" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:compModel="clr-namespace:SomeTech.DataFeed.ComponentModel;assembly=SomeTech.DataFeed" xmlns:channel="clr-namespace:SomeTech.DataFeed.Engine.Channel;assembly=SomeTech.DataFeed" xmlns:engine="clr-namespace:SomeTech.DataFeed.Engine;assembly=SomeTech.DataFeed" xmlns:kernel="clr-namespace:SomeTech.Kernel.Channel;assembly=SomeTech.Kernel" xmlns="clr-namespace:SomeTech.DataFeed;assembly=SomeTech.DataFeed" xmlns:schema="clr-namespace:System.Xml.Schema;assembly=System.Xml" xmlns:xmlLinq="clr-namespace:System.Xml.Linq;assembly=System.Xml" xmlns:domain="clr-namespace:SomeTech.Common.Domain;assembly=SomeTech.Common" xmlns:s="clr-namespace:System;assembly=mscorlib" x:Key="transportActivity" SearchType="ReportId" RecordsPerFile="100" UseWindowsAuth="false" IsWindowsAuthSpecific="false" TempFileOnErrorAction="DoNothing" TempFileOnErrorRenameString="">
    </transporters:SomeWebServiceTransportActivity>
  </DontNeed2>
  <InterestingData>
    <Items>
      <Item>Apple</Item>
    </Items>
    <Items>
      <Item>Orange</Item>
    </Items>
  </InterestingData>
</Root>

SomeTech.xsl

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <tr bgcolor="#cccccc">
            <th style="text-align:left">Item</th>
          </tr>
          <xsl:for-each select="Root/InterestingData/Items">
            <tr>
              <td>
                <xsl:value-of select="Item"/>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

SomeTech.html

<html>
<head>
    <title>Demo XSLT</title>
    <script>
        function loadXMLDoc(filename) {
            if (window.ActiveXObject) {
                xhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            else {
                xhttp = new XMLHttpRequest();
            }
            xhttp.open("GET", filename, false);
            try { xhttp.responseType = "msxml-document" } catch (err) { } // Helping IE11
            xhttp.send("");
            return xhttp.responseXML;
        }


        function displayResult() {
            xml = loadXMLDoc("SomeTech.xml");
            xsl = loadXMLDoc("SomeTech.xsl");

            // code for IE
            if (window.ActiveXObject || xhttp.responseType == "msxml-document") {
                ex = xml.transformNode(xsl);
                document.getElementById("example").innerHTML = ex;
            }
                // code for Chrome, Firefox, Opera, etc.
            else if (document.implementation && document.implementation.createDocument) {
                xsltProcessor = new XSLTProcessor();
                xsltProcessor.importStylesheet(xsl);
                resultDocument = xsltProcessor.transformToFragment(xml, document);
                document.getElementById("example").appendChild(resultDocument);
            }
        }
    </script>
</head>
<body onload="displayResult()">
    <div id="example" />
</body>
</html>

1 个答案:

答案 0 :(得分:0)

这仅在IE9中出现问题/错误。