开发者

Changegin doctype root element to rss from html using xslt?

I'm trying to add an rss-doctype to an xml-document rendered using xslt. How do I change the root element?

This is what it currently looks like:

<!DOCTYPE html PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "about:legacy-compat"> 

I would like:

<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "about:legacy-compat">

Here is my outputnode:

开发者_如何学编程
<xsl:output
method="xml"
version="1.0"
encoding="UTF-8"
doctype-public="-//Netscape Communications//DTD RSS 0.91//EN"
indent="yes"
/>


You have to include a DTD (see http://www.stylusstudio.com/xsllist/200405/post70520.html and answer http://www.stylusstudio.com/xsllist/200405/post90520.html where David Carlisle points this out). The following is correct syntax - you will need to find a DTD

<xsl:output method="xml" indent="yes" encoding="UTF-8"
doctype-system="http://foo.org/dont.know.the.dtd"
doctype-public="-//Netscape Communications//DTD RSS 0.91//EN"/>


Here is a simple example:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"
 doctype-system="http://www.silmaril.ie/software/rss2.dtd"
 doctype-public="-//Netscape Communications//DTD RSS 0.91//EN"/>
 <xsl:template match="/">
  <rss>
   <channel/>
  </rss>
 </xsl:template>
</xsl:stylesheet>

when any XML document (not used) is processed with this transformation, the wanted, correct result is produced:

<!DOCTYPE rss
  PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://www.silmaril.ie/software/rss2.dtd">
<rss>
   <channel/>
</rss>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜