msxml fails to correctly close <link> tags d

2019-08-07 02:07发布

问题:

I'm trying to parse a RSS feed using C#, and I need to transform it with XSLT. Here's a snippet of my XSLT:

<xsl:output encoding="UTF-8" method="html" omit-xml-declaration="yes"/>
<xsl:template match="/">
    <xsl:apply-templates select="rss/channel/item" />
</xsl:template>
<xsl:template match="rss/channel/item">
    <item>
    <link><xsl:value-of select="normalize-space(./link)" /></link>
      </item>
</xsl:template>

Using a random RSS (the corriere della serra), this renders correctly with XML Spy:

<item>
<link>http://www.corriere.it/este(...)2aabc.shtml</link>
</item>
<item>
<link>http://www.corriere.it/cron(...)22a-11de-bb1e-00144f02aabc.shtml</link>
</item>
...

But when using the Microsoft .net tool (either withing my code or using the Visual Studio XSLT debugger), I get:

<item>
<link>http://www.corriere.it(...)11de-aaa2-00144f02aabc.shtml
    </item>
    <item>
    <link>http://corrieredelmezzogiorno.corriere.it/le(...)03131900.shtml
        </item>
    <item>

The </link> markup is not output at all. If I change "link" for "XXX", this works perfectly, but this is unfortunately not an option.

Any idea of what is happening here???

回答1:

Ok for those wondering, msxml doesn't close link tags while in method="html" mode. If you change the first line to

<xsl:output encoding="UTF-8" method="xml" omit-xml-declaration="yes"/>

The above code works perfectly...



标签: .net xslt msxml