msxml fails to correctly close <link> tags during XSLT transformation

别说谁变了你拦得住时间么 提交于 2019-12-24 12:08:28

问题


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...



来源:https://stackoverflow.com/questions/1472767/msxml-fails-to-correctly-close-link-tags-during-xslt-transformation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!