我是XSL的新手,对一个问题非常困惑。
我在SharePoint上有一个RSS源,它以这种格式出现:
<?xml version="1.0" encoding="UTF-8"?>
-<rss version="2.0">-
<channel>
<title>Company Name</title>
<description>Company News and Events</description>
<link>http://website.com/</link>
<item>
<title>Article</title>
<description><p>Something</p></description>
<pubDate> 12 Jan 2015</pubDate>
<link>http://website.com/news-and-knowledge/news/807</link>
<guid>http://website.com/news-and-knowledge/news/807</guid>
</item>
<item>
<title>Article</title>
<description><p>Something</p></description>
<pubDate> 20 Dec 2014</pubDate>
<link>http://website.com/news-and-knowledge/news/806</link>
<guid>http://website.com/news-and-knowledge/news/806</guid>
</item>
<item>
<title>Article</title>
<description><p>Something</p></description>
<pubDate> 13 Dec 2014</pubDate>
<link>http://website.com/news-and-knowledge/news/805</link>
<guid>http://website.com/news-and-knowledge/news/805</guid>
</item>
</channel>
</rss>
我有我的RSS阅读器,它会生成一个大的列表,但是我想在有新的月份时放入休息。即,在上面的例子中,它将输出:
Jan 2015
•文章标题标题标题
Dec 2014
•文章标题标题标题
•文章标题标题标题
我的代码打印了每条记录的日期如下。我只需要一种比较PrevPosition.pubDate和CurPosition.pubDate
的方法<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
version="1.0" exclude-result-prefixes="xsl ddwrt msxsl rssaggwrt"
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
xmlns:rssaggwrt="http://schemas.microsoft.com/WebParts/v3/rssagg/runtime"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:rssFeed="urn:schemas-microsoft-com:sharepoint:RSSAggregatorWebPart">
<xsl:param name="rss_FeedLimit">30</xsl:param>
<xsl:param name="rss_ExpandFeed">true</xsl:param>
<xsl:param name="rss_LCID">1033</xsl:param>
<xsl:param name="rss_WebPartID">RSS_Viewer_WebPart</xsl:param>
<xsl:param name="rss_alignValue">left</xsl:param>
<xsl:param name="rss_IsDesignMode">True</xsl:param>
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="Rows" select="channel/item"/>
<xsl:variable name="RowCount" select="count($Rows)"/>
<div>
<xsl:apply-templates select="rss/channel"/>
</div>
</xsl:template>
<xsl:template match="rss/channel">
<xsl:variable name="link" select="link"/>
<xsl:variable name="description" select="description"/>
<ul>
<xsl:apply-templates select="item"/>
</ul>
</xsl:template>
<xsl:template match="item">
<xsl:variable name="Rows" select="channel/item"/>
<xsl:variable name="RowCount" select="count($Rows)"/>
<xsl:variable name="item_link" select="link"/>
<xsl:variable name="item_title" select="description"/>
<xsl:for-each select="$Rows"/>
<xsl:variable name="CurPosition" select="position()" />
<xsl:variable name="PrevPosition" select="position()-1" />
<xsl:variable name="RssFeedLink" select="$rss_WebPartID" />
<xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
<xsl:if test="not(substring(pubDate,3,9) = 0)">
<div align="center">
<hr/>
<xsl:value-of select="substring(pubDate,3,9)" disable-output-escaping="yes"/>
</div>
</xsl:if>
<li>
<a href="{$item_link}" title="{$item_title}">
<xsl:variable name="SafeHtml">
<xsl:call-template name="GetSafeHtml">
<xsl:with-param name="Html" select="title"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$SafeHtml" disable-output-escaping="yes"/>
</a>
</li>
</xsl:template>
<xsl:template name="GetSafeHtml">
<xsl:param name="Html"/>
<xsl:choose>
<xsl:when test="$rss_IsDesignMode = 'True'">
<xsl:value-of select="$Html"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="rssaggwrt:MakeSafe($Html)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
这段代码是我在网上找到的东西的混合物,以及我知道从我运行的另一个Feed中工作的东西。如果只有一些方法可以说:
when
CurPosition.substring(pubDate,3,9) <>= PrevPosition.substring(pubDate,3,9)
System.Out.Println(substring($pubDate,3,9))
Else ()
但不幸的是,这是3种语言的组合,可能在语法上不正确!
非常感谢任何帮助
答案 0 :(得分:0)
如果只有某种方式可以说:
当CurPosition.substring(pubDate,3,9)&lt;&gt; =
时PrevPosition.substring(pubDate,3,9)&gt;
System.Out.Println(substring($ pubDate,3,9))Else()
XSLT中的等价物是:
<xsl:choose>
<xsl:when test="substring(//pubDate[position()], 3, 9) != substring(//pubDate[position() - 1], 3, 9)">
<hr/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
<xsl:value-of select="//pubDate"/>
<强>参考强>