C# WinRT中的XsltProcessor不起作用,但Windows 10通用应用程序中的同一类起作用

C# WinRT中的XsltProcessor不起作用,但Windows 10通用应用程序中的同一类起作用,c#,xslt,windows-runtime,C#,Xslt,Windows Runtime,下面的代码适用于我在Windows10通用应用程序中尝试过的所有示例。但在Windows8.1应用程序中,除了xml文档声明和内部xml之外,它不会从xsl模板输出任何静态html内容 你知道为什么它在WinRT中会这样吗 private static string TransformToString(string xml, string xsl) { var xmlDocument = new XmlDocument(); xmlDocument

下面的代码适用于我在Windows10通用应用程序中尝试过的所有示例。但在Windows8.1应用程序中,除了xml文档声明和内部xml之外,它不会从xsl模板输出任何静态html内容

你知道为什么它在WinRT中会这样吗

    private static string TransformToString(string xml, string xsl)
    {
        var xmlDocument = new XmlDocument();
        xmlDocument.LoadXml(xml);

        var xslDocument = new XmlDocument();
        xslDocument.LoadXml(xsl);

        var processor = new XsltProcessor(xslDocument);

        //string transformation = processor.TransformToString(xmlDocument.LastChild);
        string transformation = processor.TransformToString(xmlDocument);

        return transformation;
    }
示例xml:

<library xmlns='http://www.microsoft.com'>
    <book>
        <chapter></chapter>
        <chapter>
            <section>
                <paragraph a="b">1</paragraph>
                <paragraph a="b">2</paragraph>
            </section>
        </chapter>
    </book>
</library>

1.
2.
示例xsl:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:m="http://www.microsoft.com">
<xsl:template match="/">
    <html><body><table>
    <tr>
    <td>Attribute</td>
    <td>Value</td>
    </tr>
    <xsl:for-each select="m:library/m:book/m:chapter/m:section/m:paragraph">
    <tr>
    <td><xsl:value-of select="@a"/></td>
    <td><xsl:value-of select="."/></td>
    </tr>
    </xsl:for-each>
    </table></body></html>
</xsl:template>

属性
价值

结果

<?xml version="1.0" encoding="utf-8"?>12
12

问题是用
xmlDocument.LastChild
而不是
xmlDocument
调用
TransformToString

为什么
processor.TransformToString(xmlDocument.LastChild)
,为什么不调用
processor.TransformToString(xmlDocument)
?我们真的需要看到完整的XSLT。谢谢@MartinHonnen!在
XmlDocument
的子元素上进行转换确实是个问题。现在很好用。