【发布时间】:2013-04-22 14:38:28
【问题描述】:
我对 xsl 还很陌生,正在尝试找到一种方法来隐藏或静音 wordpress rss 提要的 xml 中除了两个节点之外的所有节点,结构如下:
?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
<title>Title</title>
<atom:link href="http://www.alink.com" rel="self" type="application/rss+xml" />
<link>http://www.alink.com</link>
<description>Just another WordPress site</description>
<lastBuildDate>Sun, 21 Apr 2013 22:13:55 +0000</lastBuildDate>
<language>en-US</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>http://wordpress.org/?v=3.5.1</generator>
<item>
<title>A Title</title>
<link>http://www.alink.com</link>
<comments>comments</comments>
<pubDate>Sun, 21 Apr 2013 22:13:55 +0000</pubDate>
<dc:creator>aUser</dc:creator>
<category><![CDATA[Uncategorized]]></category>
<guid isPermaLink="false">http://www5.uifoundation.org/news/?p=112</guid>
<description><![CDATA[Post[...]]]></description>
<content:encoded> Posted October 10, 2013 </content:encoded>
<wfw:commentRss>http://www.alink.com</wfw:commentRss>
<slash:comments>0</slash:comments>
</item>
但我只想在我的转换中显示频道/标题和频道/链接。我正在考虑在所有节点上使用空模板,就像这样
<xsl:template match="channel/* EXCEPTION channel/item/title | channel/item/link" />
我不确定如何声明异常。如果有更好的方法,我也愿意接受
我真的只是希望输出是item/title 的无序列表,其值为item/link,其他所有内容都隐藏。输出示例如下:
<ul>
<li>
<a href= "www.aLink.com">A Title</a>
</li>
</ul>
【问题讨论】:
-
您希望
rss和channel也包含在输出中吗?所需的确切输出示例会有所帮助。 -
我真的只是希望输出是项目/标题的无序列表,项目/链接的值,其他所有内容都隐藏,所以输出的一个例子是:
-
最好编辑您的问题以显示所需的输出。我想现在我明白了你想要什么输出,答案会完全不同。
标签: xml xslt xml-parsing rss