Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将rss提要转换为xml时的XSLT问题_Xml_Xslt_Transformation - Fatal编程技术网

将rss提要转换为xml时的XSLT问题

将rss提要转换为xml时的XSLT问题,xml,xslt,transformation,Xml,Xslt,Transformation,这是我的xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1990/XSL/Transform" version="1.0"> <xsl:output method="xml" version="2.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <

这是我的xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1990/XSL/Transform" version="1.0">
<xsl:output method="xml" version="2.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:element name="root">
<xsl:apply-template select="rss/channel/item/pubDate"/>
</xsl:element>
</xsl:template>

<xsl:template match="rss/channel/item/pubDate">
<xsl:element name="rawr" >
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

以下是我以xml形式阅读的rss提要:

令人恼火的是,我没有收到任何错误信息;我什么也得不到

我期望的输出如下所示:

<root>
<rawr>
<pubDate>
22/12/1766
</pubDate>
</rawr>
</root>

22/12/1766

任何指导都将不胜感激

两项。首先,你需要改变

xmlns:xsl="http://www.w3.org/1990/XSL/Transform"
<xsl:template match="rss/channel/item/pubDate">
    <xsl:element name="rawr" >
        <xsl:value-of select="."/>
    </xsl:element>
</xsl:template>




如果您想添加两项。首先,你需要改变

xmlns:xsl="http://www.w3.org/1990/XSL/Transform"
<xsl:template match="rss/channel/item/pubDate">
    <xsl:element name="rawr" >
        <xsl:value-of select="."/>
    </xsl:element>
</xsl:template>




如果您想添加两项。首先,你需要改变

xmlns:xsl="http://www.w3.org/1990/XSL/Transform"
<xsl:template match="rss/channel/item/pubDate">
    <xsl:element name="rawr" >
        <xsl:value-of select="."/>
    </xsl:element>
</xsl:template>




如果您想添加两项。首先,你需要改变

xmlns:xsl="http://www.w3.org/1990/XSL/Transform"
<xsl:template match="rss/channel/item/pubDate">
    <xsl:element name="rawr" >
        <xsl:value-of select="."/>
    </xsl:element>
</xsl:template>



如果要添加

我没有收到错误消息;我什么也得不到

那么问题就出在别处了。如果以传入提要为例:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/shared/bsp/xsl/rss/nolsol.xsl"?>

<rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">  
  <channel> 
    <title>BBC News - Home</title>  
    <link>http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
    <description>The latest stories from the Home section of the BBC News web site.</description>  
    <language>en-gb</language>  
    <lastBuildDate>Tue, 29 Apr 2014 14:07:47 GMT</lastBuildDate>  
    <copyright>Copyright: (C) British Broadcasting Corporation, see http://news.bbc.co.uk/2/hi/help/rss/4498287.stm for terms and conditions of reuse.</copyright>  
    <image> 
      <url>http://news.bbcimg.co.uk/nol/shared/img/bbc_news_120x60.gif</url>  
      <title>BBC News - Home</title>  
      <link>http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <width>120</width>  
      <height>60</height> 
    </image>  
    <ttl>15</ttl>  
    <atom:link href="http://feeds.bbci.co.uk/news/rss.xml" rel="self" type="application/rss+xml"/>  
    <item> 
      <title>Stabbed teacher was due to retire</title>  
      <description>A teacher stabbed to death in front of her pupils at a Leeds school is described by the head teacher as "inspirational", as it emerges she was to retire this year.</description>  
      <link>http://www.bbc.co.uk/news/uk-england-27201812#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <guid isPermaLink="false">http://www.bbc.co.uk/news/uk-england-27201812</guid>  
      <pubDate>Tue, 29 Apr 2014 14:11:45 GMT</pubDate>  
      <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/74515000/jpg/_74515871_74499402.jpg"/>  
      <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/74515000/jpg/_74515872_74499402.jpg"/> 
    </item>  
    <item> 
      <title>UK economy grows by 0.8% in quarter</title>  
      <description>UK economy grows 0.8% in first quarter of 2014, the fifth consecutive quarter of growth, according to the ONS.</description>  
      <link>http://www.bbc.co.uk/news/business-27203433#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <guid isPermaLink="false">http://www.bbc.co.uk/news/business-27203433</guid>  
      <pubDate>Tue, 29 Apr 2014 11:26:59 GMT</pubDate>  
      <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/74508000/jpg/_74508863_brompton1.g.jpg"/>  
      <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/74508000/jpg/_74508864_brompton1.g.jpg"/> 
    </item>  
    <item> 
      <title>Rebels seize regional Ukraine HQ</title>  
      <description>A large crowd of pro-Russian activists storms the regional administration's headquarters in the eastern Ukrainian city of Luhansk.</description>  
      <link>http://www.bbc.co.uk/news/world-europe-27206280#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <guid isPermaLink="false">http://www.bbc.co.uk/news/world-europe-27206280</guid>  
      <pubDate>Tue, 29 Apr 2014 13:53:23 GMT</pubDate>  
      <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/74518000/jpg/_74518092_022076576-1.jpg"/>  
      <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/74518000/jpg/_74518093_022076576-1.jpg"/> 
    </item>  
    <item> 
      <title>Steel 'quizzed Smith on sex claims'</title>  
      <description>Lord Steel says he challenged Cyril Smith about allegations he abused boys after they appeared in Private Eye in 1979.</description>  
      <link>http://www.bbc.co.uk/news/uk-politics-27203110#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <guid isPermaLink="false">http://www.bbc.co.uk/news/uk-politics-27203110</guid>  
      <pubDate>Tue, 29 Apr 2014 13:28:10 GMT</pubDate>  
      <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/74515000/jpg/_74515070_74509905.jpg"/>  
      <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/74515000/jpg/_74515071_74509905.jpg"/> 
    </item>  
  </channel> 
</rss>

英国广播公司新闻-主页
http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
BBC新闻网站首页的最新报道。
欧洲标准
2014年4月29日星期二14:07:47 GMT
版权所有:(C)英国广播公司,见http://news.bbc.co.uk/2/hi/help/rss/4498287.stm 重复使用的条款和条件。
http://news.bbcimg.co.uk/nol/shared/img/bbc_news_120x60.gif  
英国广播公司新闻-主页
http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
120
60
15
被刺伤的老师即将退休
利兹一所学校的一名教师在学生面前被刺死,校长称她是“鼓舞人心的”,因为她将于今年退休。
http://www.bbc.co.uk/news/uk-england-27201812#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
http://www.bbc.co.uk/news/uk-england-27201812  
2014年4月29日星期二14:11:45 GMT
英国经济第二季度增长0.8%
英国国家统计局的数据显示,2014年第一季度英国经济增长0.8%,连续第五个季度增长。
http://www.bbc.co.uk/news/business-27203433#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
http://www.bbc.co.uk/news/business-27203433  
2014年4月29日星期二11:26:59 GMT
叛军占领乌克兰地区总部
乌克兰东部城市卢汉斯克的地方政府总部遭到大批亲俄活动分子的袭击。
http://www.bbc.co.uk/news/world-europe-27206280#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
http://www.bbc.co.uk/news/world-europe-27206280  
2014年4月29日星期二13:53:23 GMT
斯蒂尔“对史密斯的性主张进行了调查”
斯蒂尔勋爵说,他对西里尔·史密斯(Cyril Smith)在1979年《私人侦探》(Private Eye)中出现后虐待男孩的指控提出质疑。
http://www.bbc.co.uk/news/uk-politics-27203110#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
http://www.bbc.co.uk/news/uk-politics-27203110  
2014年4月29日星期二13:28:10 GMT
并对其应用样式表的更正版本:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
<xsl:element name="root">
<xsl:apply-templates select="rss/channel/item/pubDate"/>
</xsl:element>
</xsl:template>

<xsl:template match="rss/channel/item/pubDate">
<xsl:element name="rawr" >
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

您应该得到以下结果:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <rawr>Tue, 29 Apr 2014 14:11:45 GMT</rawr>
   <rawr>Tue, 29 Apr 2014 11:26:59 GMT</rawr>
   <rawr>Tue, 29 Apr 2014 13:53:23 GMT</rawr>
   <rawr>Tue, 29 Apr 2014 13:28:10 GMT</rawr>
</root>

2014年4月29日星期二14:11:45 GMT
2014年4月29日星期二11:26:59 GMT
2014年4月29日星期二13:53:23 GMT
2014年4月29日星期二13:28:10 GMT
即使使用原始样式表,您也应该会收到一条错误消息——因此请检查您实现转换的方式

我没有收到错误消息;我什么也得不到

那么问题就出在别处了。如果以传入提要为例:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/shared/bsp/xsl/rss/nolsol.xsl"?>

<rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">  
  <channel> 
    <title>BBC News - Home</title>  
    <link>http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
    <description>The latest stories from the Home section of the BBC News web site.</description>  
    <language>en-gb</language>  
    <lastBuildDate>Tue, 29 Apr 2014 14:07:47 GMT</lastBuildDate>  
    <copyright>Copyright: (C) British Broadcasting Corporation, see http://news.bbc.co.uk/2/hi/help/rss/4498287.stm for terms and conditions of reuse.</copyright>  
    <image> 
      <url>http://news.bbcimg.co.uk/nol/shared/img/bbc_news_120x60.gif</url>  
      <title>BBC News - Home</title>  
      <link>http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <width>120</width>  
      <height>60</height> 
    </image>  
    <ttl>15</ttl>  
    <atom:link href="http://feeds.bbci.co.uk/news/rss.xml" rel="self" type="application/rss+xml"/>  
    <item> 
      <title>Stabbed teacher was due to retire</title>  
      <description>A teacher stabbed to death in front of her pupils at a Leeds school is described by the head teacher as "inspirational", as it emerges she was to retire this year.</description>  
      <link>http://www.bbc.co.uk/news/uk-england-27201812#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <guid isPermaLink="false">http://www.bbc.co.uk/news/uk-england-27201812</guid>  
      <pubDate>Tue, 29 Apr 2014 14:11:45 GMT</pubDate>  
      <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/74515000/jpg/_74515871_74499402.jpg"/>  
      <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/74515000/jpg/_74515872_74499402.jpg"/> 
    </item>  
    <item> 
      <title>UK economy grows by 0.8% in quarter</title>  
      <description>UK economy grows 0.8% in first quarter of 2014, the fifth consecutive quarter of growth, according to the ONS.</description>  
      <link>http://www.bbc.co.uk/news/business-27203433#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <guid isPermaLink="false">http://www.bbc.co.uk/news/business-27203433</guid>  
      <pubDate>Tue, 29 Apr 2014 11:26:59 GMT</pubDate>  
      <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/74508000/jpg/_74508863_brompton1.g.jpg"/>  
      <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/74508000/jpg/_74508864_brompton1.g.jpg"/> 
    </item>  
    <item> 
      <title>Rebels seize regional Ukraine HQ</title>  
      <description>A large crowd of pro-Russian activists storms the regional administration's headquarters in the eastern Ukrainian city of Luhansk.</description>  
      <link>http://www.bbc.co.uk/news/world-europe-27206280#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <guid isPermaLink="false">http://www.bbc.co.uk/news/world-europe-27206280</guid>  
      <pubDate>Tue, 29 Apr 2014 13:53:23 GMT</pubDate>  
      <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/74518000/jpg/_74518092_022076576-1.jpg"/>  
      <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/74518000/jpg/_74518093_022076576-1.jpg"/> 
    </item>  
    <item> 
      <title>Steel 'quizzed Smith on sex claims'</title>  
      <description>Lord Steel says he challenged Cyril Smith about allegations he abused boys after they appeared in Private Eye in 1979.</description>  
      <link>http://www.bbc.co.uk/news/uk-politics-27203110#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa</link>  
      <guid isPermaLink="false">http://www.bbc.co.uk/news/uk-politics-27203110</guid>  
      <pubDate>Tue, 29 Apr 2014 13:28:10 GMT</pubDate>  
      <media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/74515000/jpg/_74515070_74509905.jpg"/>  
      <media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/74515000/jpg/_74515071_74509905.jpg"/> 
    </item>  
  </channel> 
</rss>

英国广播公司新闻-主页
http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
BBC新闻网站首页的最新报道。
欧洲标准
2014年4月29日星期二14:07:47 GMT
版权所有:(C)英国广播公司,见http://news.bbc.co.uk/2/hi/help/rss/4498287.stm 重复使用的条款和条件。
http://news.bbcimg.co.uk/nol/shared/img/bbc_news_120x60.gif  
英国广播公司新闻-主页
http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
120
60
15
被刺伤的老师即将退休
利兹一所学校的一名教师在学生面前被刺死,校长称她是“鼓舞人心的”,因为她将于今年退休。
http://www.bbc.co.uk/news/uk-england-27201812#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
http://www.bbc.co.uk/news/uk-england-27201812  
2014年4月29日星期二14:11:45 GMT
英国经济第二季度增长0.8%
英国国家统计局的数据显示,2014年第一季度英国经济增长0.8%,连续第五个季度增长。
http://www.bbc.co.uk/news/business-27203433#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
http://www.bbc.co.uk/news/business-27203433  
2014年4月29日星期二11:26:59 GMT
叛军占领乌克兰地区总部
乌克兰东部城市卢汉斯克的地方政府总部遭到大批亲俄活动分子的袭击。
http://www.bbc.co.uk/news/world-europe-27206280#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
http://www.bbc.co.uk/news/world-europe-27206280  
2014年4月29日星期二13:53:23 GMT
斯蒂尔“对史密斯的性主张进行了调查”
斯蒂尔勋爵说,他对西里尔·史密斯(Cyril Smith)在1979年《私人侦探》(Private Eye)中出现后虐待男孩的指控提出质疑。
http://www.bbc.co.uk/news/uk-politics-27203110#sa-ns_mchannel=rss&;ns_来源=PublicRSS20 sa
http://www.bbc.co.uk/news/uk-politics-27203110  
4月29日星期二