DNN:使用XSL通过DNN XML模块在4列中提供RSS

时间:2013-03-10 22:04:24

标签: xml xslt rss dotnetnuke dotnetnuke-6

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

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

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

提前感谢您的关注!

我在这里:

    <?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>

1 个答案:

答案 0 :(得分: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>