0

我尝试格式化来自我的 DNN 站点的 RSS 提要并使其看起来不错。我想在 4 列中显示内容:

https://dl.dropbox.com/u/38410375/liste.png

我需要一个 XSL 文件以在 DNN XML 模块中使用,但无法使其工作。我不确定我已经拥有的代码是否有意义,但这就是我迄今为止在网上找到的。我希望这里有人可以将我推向正确的方向,因为我收到的错误消息对我来说非常神秘。

提前感谢您的关注!

这是我所拥有的:

    <?xml-stylesheet type="text/xsl" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:param name="ItemsToShow"/>
<xsl:param name="ShowItemDetails"/>
<xsl:param name="ShowItemDate"/>
<xsl:param name="Locale"/>
<xsl:template match="rss">
    <table>
        <xsl:for-each select="channel/item[position()=$ItemsToShow or $ItemsToShow]"/>
        <div class="DNN_News_Item">
            <div class="DNN_News_ItemDate">
                <xsl:if test="$ShowItemDate='true'">
                    <xsl:value-of select="pubDate"/>
                </xsl:if>
                <xsl:if test="$ShowItemDate='true'">
<xsl:text>
- 
</xsl:text>
                </xsl:if>
            </div>
            <div class="DNN_News_ItemLink">
                <a href="{link}" target="_blank">
                    <xsl:value-of select="title"/>
                </a>
            </div>
            <xsl:if test="$ShowItemDetails='true'">
                <div class="DNN_News_ItemDetails">
                    <a href="{link}" target="_blank">
                        <xsl:value-of select="description" disable-output-escaping="yes"/>
                    </a>
                </div>
            </xsl:if>
        </div>
    </table>
</xsl:template>
<xsl:template match="rss" mode="tr">
    <tr>
        <xsl:apply-templates select="." mode="td"/>
        <xsl:apply-templates select="following-sibling::*[position() &lt; 4]" mode="td"/>
    </tr>
    <xsl:apply-templates select="following-sibling::*[4]" mode="tr"/>
</xsl:template>
<xsl:template match="rss" mode="td">
    <td>
        <xsl:apply-templates select="text()"/>
    </td>
</xsl:template>

4

1 回答 1

0

这是你想要的吗?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes"/>
  <xsl:param name="ItemsToShow" select="5"/>
  <xsl:param name="ShowItemDetails" select="'true'"/>
  <xsl:param name="ShowItemDate"/>
  <xsl:param name="Locale"/>
  <xsl:template match="rss">
    <table>
      <xsl:apply-templates select="channel/item[position() &lt;= $ItemsToShow or 
                                                not($ItemsToShow)]
                                               [position() mod 4 = 1]"
                           mode="row"/>
    </table>
  </xsl:template>

  <xsl:template match="item" mode="row">
    <tr>
      <xsl:apply-templates select=". | following-sibling::item[position() &lt; 4]" 
                           mode="cell"/>
    </tr>
  </xsl:template>

  <xsl:template match="item" mode="cell">
    <td>
      <div class="DNN_News_Item">
        <div class="DNN_News_ItemDate">
          <xsl:apply-templates select="pubDate[$ShowItemDate='true']" />
          <xsl:apply-templates select="pubDate[not($ShowItemDate='true')]"
                               mode="noDate" />
        </div>
        <div class="DNN_News_ItemLink">
          <a href="{link}" target="_blank">
            <xsl:value-of select="title"/>
          </a>
        </div>
        <xsl:apply-templates select="self::node()[$ShowItemDetails = 'true']" 
                             mode="details" />
      </div>
    </td>
  </xsl:template>

  <xsl:template match="item" mode="details">
    <div class="DNN_News_ItemDetails">
      <a href="{link}" target="_blank">
        <xsl:value-of select="description" disable-output-escaping="yes" />
      </a>
    </div>
  </xsl:template>

  <xsl:template match="pubDate" mode="noDate">
    <xsl:text>-</xsl:text>
  </xsl:template>
</xsl:stylesheet>

在该 RSS 提要的 XML 上运行时,结果是:

<table>
  <tr>
    <td>
      <div class="DNN_News_Item">
        <div class="DNN_News_ItemDate">-</div>
        <div class="DNN_News_ItemLink"><a href="http://literatura24.com/Default.aspx?tabid=436&amp;fileshareact=viewfile&amp;Fileid=2" target="_blank">Historias Sem Data</a></div>
        <div class="DNN_News_ItemDetails"><a href="http://literatura24.com/Default.aspx?tabid=436&amp;fileshareact=viewfile&amp;Fileid=2" target="_blank">
        <img alt="" src="http://literatura24.com/Portals/4/ebooks-pictures/machado_de_assis-historias_sem_data.jpg" style="margin-right: 5px;" align="left" width="100" height="166" />Autor: Assis, Machado de, 1839-1908<br />
        T&iacute;tulo: Historias Sem Data<br />
        Idioma: Portugu&ecirc;s<br />
        Assunto:<br />
        Dispon&iacute;vel como: EPUB e KINDLE
      </a></div>
      </div>
    </td>
    <td>
      <div class="DNN_News_Item">
        <div class="DNN_News_ItemDate">-</div>
        <div class="DNN_News_ItemLink"><a href="http://literatura24.com/Default.aspx?tabid=436&amp;fileshareact=viewfile&amp;Fileid=1" target="_blank">Os Lusíadas</a></div>
        <div class="DNN_News_ItemDetails"><a href="http://literatura24.com/Default.aspx?tabid=436&amp;fileshareact=viewfile&amp;Fileid=1" target="_blank">
        <p><img alt="" src="http://literatura24.com/Portals/4/ebooks-pictures/220px-Os_Lus%C3%ADadas.jpg" style="margin-right: 5px;" align="left" width="100" height="156" />Autor: Cam&otilde;es, Lu&iacute;s Vaz de, 1524-1580<br />
        T&iacute;tulo: Os Lus&iacute;adas<br />
        Idioma: Portugu&ecirc;s<br />
        Assunto: poesia Portugu&ecirc;s<br />
        Dispon&iacute;vel como: EPUB e KINDLE<br />
        <br />
        </p>
      </a></div>
      </div>
    </td>
    <td>
      <div class="DNN_News_Item">
        <div class="DNN_News_ItemDate">-</div>
        <div class="DNN_News_ItemLink"><a href="http://literatura24.com/Default.aspx?tabid=436&amp;fileshareact=viewfile&amp;Fileid=4" target="_blank">The Adventures of Sherlock Holmes</a></div>
        <div class="DNN_News_ItemDetails"><a href="http://literatura24.com/Default.aspx?tabid=436&amp;fileshareact=viewfile&amp;Fileid=4" target="_blank">
        <img alt="" src="http://literatura24.com/Portals/4/ebooks-pictures/399365_Memoirs-of-Sherlock-Holmes-book-jacket.jpg" height="150" align="left" width="100" />Autor: Doyle, Arthur Conan, Sir, 1859-1930<br />
        T&iacute;tulo: The Adventures of Sherlock Holmes<br />
        Idioma: Ingl&ecirc;s<br />
        Assunto: detetive e mist&eacute;rio<br />
        Dispon&iacute;vel como: EPUB e KINDLE
      </a></div>
      </div>
    </td>
    <td>
      <div class="DNN_News_Item">
        <div class="DNN_News_ItemDate">-</div>
        <div class="DNN_News_ItemLink"><a href="http://literatura24.com/Default.aspx?tabid=436&amp;fileshareact=viewfile&amp;Fileid=3" target="_blank">Viagens na Minha Terra</a></div>
        <div class="DNN_News_ItemDetails"><a href="http://literatura24.com/Default.aspx?tabid=436&amp;fileshareact=viewfile&amp;Fileid=3" target="_blank">
        <img alt="" src="http://literatura24.com/Portals/4/ebooks-pictures/41606_500.jpg" style="margin-right: 5px;" align="left" width="100" height="139" />Autor: Almeida Garrett, Jo&atilde;o Batista da Silva Leit&atilde;o de, Visconde de, 1799-1854<br />
        T&iacute;tulo: Viagens na Minha Terra (Completo)<br />
        Idioma: Portugu&ecirc;s<br />
        Assunto: fic&ccedil;&atilde;o Portugu&ecirc;s<br />
        Dispon&iacute;vel como: EPUB e KINDLE
      </a></div>
      </div>
    </td>
  </tr>
</table>
于 2013-03-11T17:33:59.907 回答