0

我有这个现有的 xsl 用于呈现 RSS 提要。
除了标题之外,其他所有内容都从描述字段中解析出来。
下面的片段是目前的完成方式。它可以工作,但没有设置项目的顺序。如何修改我拥有的内容,以便项目按itemPubDate. 一个样本itemPubDate值为06/26/2013

<xsl:template name="RSSMainTemplate.body">
    <xsl:param name="Rows" />
    <xsl:param name="RowCount" />
    <xsl:for-each select="$Rows">
        <xsl:variable name="CurPosition" select="position()" />
        <xsl:variable name="RssFeedLink" select="$rss_ID" />
        <xsl:variable name="CurrentElement" select="concat($RssFeedLink,$CurPosition)" />
        <xsl:call-template name="RSSDescTransform1">
            <xsl:with-param name="DescriptionField" select="description" />
        </xsl:call-template>
    </xsl:for-each>
</xsl:template>

<xsl:template name="RSSDescTransform1">
    <xsl:param name="DescriptionField" />
    <xsl:variable name="itemTitle" select="title" />
    <xsl:variable name="itemAuthor" select="substring-before(substring-after($DescriptionField, 'itemAuthor:&lt;/b&gt; '),'&lt;/div&gt;')" />
    <xsl:variable name="itemPubDate" select="substring-before(substring-after($DescriptionField, 'itemPubDate:&lt;/b&gt; '),'&lt;/div&gt;')" />
    <xsl:variable name="itemDescription" select="substring-before(substring-after($DescriptionField, 'itemDescription:&lt;/b&gt; '),'&lt;/div&gt;')" />
    <xsl:variable name="itemHTML" select="substring-after($DescriptionField, 'itemHTML:&lt;/b&gt; ')" />
    <xsl:variable name="itemLink" select="substring-before(substring-after($DescriptionField, 'href=&quot;'),'&quot;')" />
    <xsl:call-template name="RSSDescTransform2">
        <xsl:with-param name="itemTitle" select="$itemTitle" />
        <xsl:with-param name="itemAuthor" select="$itemAuthor" />
        <xsl:with-param name="itemPubDate" select="$itemPubDate" />
        <xsl:with-param name="itemDescription" select="$itemDescription" />
        <xsl:with-param name="itemLink" select="$itemLink" />
        <xsl:with-param name="itemHTML" select="$itemHTML" /></xsl:call-template>
</xsl:template>

完整的 XSL这里

我目前没有输入示例,但它看起来像

<item>
  <title>lorem ipsum</title>
  <description>
    <![CDATA[
      <div>
        itemAuthor:<b>John</b>
        itemPubDate:<b>06/26/2013</b>
        ...
      </div>
    ]]>
  <description>
</item>
<item>
  ...
</item>

输出几乎相同,只是使用了一些 CSS 样式。


XSL 现在不会导致任何错误。我只是想让项目按itemPubDate

4

1 回答 1

2

您应该能够在 RSSMainTemplate.body 模板中的 for-each 中应用排序。关键是提取日期部分(年、月、日),并分别对每个部分进行排序

<xsl:for-each select="$Rows">
       <xsl:sort select="substring(substring-before(substring-after(description, 'itemPubDate:&lt;b&gt;'),'&lt;/b&gt;'),7,4)"  />
       <xsl:sort select="substring(substring-before(substring-after(description, 'itemPubDate:&lt;b&gt;'),'&lt;/b&gt;'),4,2)"  />
       <xsl:sort select="substring(substring-before(substring-after(description, 'itemPubDate:&lt;b&gt;'),'&lt;/b&gt;'),1,2)"  />

我还注意到您的 select 语句中存在从 div 中提取信息的问题(基于您的示例 XML),您在其中

<xsl:variable name="itemPubDate" select="substring-before(substring-after($DescriptionField, 'itemPubDate:&lt;/b&gt; '),'&lt;/div&gt;')" />

它应该是

<xsl:variable name="itemPubDate" select="substring-before(substring-after($DescriptionField, 'itemPubDate:&lt;b&gt;'),'&lt;/b&gt;')" />
于 2013-07-23T04:54:01.073 回答