简体   繁体   English

带有mod的XSL表输出

[英]XSL table output with mod

I'm trying to output a table using XSL from a list of articles in the following format. 我正在尝试使用XSL从以下格式的文章列表中输出表格。 The needs to be repeated, so full, split, split, full, split, split, etc. 需要重复执行,因此需要完全,拆分,拆分,完全,拆分,拆分等。

<table>
    <tr>
        <td>Full</td>
    </tr>
    <tr>
        <td>Split</td>
        <td>Split</td>
    </tr>
    ... 
</table>

So the 1st and every forth article is a full article, but the rest are split articles and that row would contain 2x td's, not just one. 因此,第1条和第4条都是完整的文章,而其余文章是拆分文章,并且该行将包含2x td,而不仅仅是一个。

If I was doing this is PHP or similar I'd conditionally add the opening and closing tr's as required. 如果我使用的是PHP或类似的软件,则可以有条件地根据需要添加打开和关闭tr。 It seems I can't do that in XSL. 看来我无法在XSL中做到这一点。 So I don't think I can use xsl:if on the tr's. 所以我认为我不能在tr上使用xsl:if。

<xsl:choose>
<xsl:when test="position() mod 4 = 0 or position() = 1">
    <tr>
        <td>Full</td>
    </tr>        
</xsl:when>
<xsl:otherwise>
    <tr>
        <td>Split</td>
    </tr>
</xsl:otherwise>
</xsl:choose>

Can anyone point me in the right direction? 谁能指出我正确的方向?

Many thanks 非常感谢

EDIT Here is the XML 编辑这是XML

<?xml-stylesheet type="text/xsl" href="template.xsl" version="1.0"?>
<rss version="2.0">
  <channel>
    <title>August 2011</title>
    <link>http://newsletters.falmouth.ac.uk/829a80a6-d28f-4f69-88e7-6177391b7eba/issue.aspx</link>
    <publication>Alumni e-Newsletter</publication>
    <publicationDescription>Alumni e-Newsletter</publicationDescription>
    <description>The school holidays are upon us and one thing that’s guaranteed is that the weather will be as unpredictable as ever!  But fear not, the Maritime Museum has the perfect solution for keeping the kids entertained come rain or shine.</description>
    <language>en-gb</language>
    <category>Alumni e-Newsletter</category>
    <generator />
    <lastBuildDate>Thu, 26 Jan 2012 14:03:46 GMT</lastBuildDate>
    <copyright>Copyright: (C) University College Falmouth</copyright>
    <ttl>15</ttl>
    <image>
      <title>This is a caption</title>
      <url>http://newsletters.falmouth.ac.uk/uploads/59026aae-27f8-4682-987f-632f1b4b6f77.jpg</url>
    </image>

    <item id="785">
      <title>Summer Holiday Activities 001</title>
      <link>http://www.nmmc.co.uk/newsletter/link.php?M=10940&amp;N=165&amp;L=248&amp;F=H</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Until 4 September&lt;/STRONG&gt;&lt;BR&gt;Our school holiday activities are well under way and there are lots more to come.&amp;nbsp; Every week has a different theme and every day there’s a new creative craft activity to try.&amp;nbsp; And don’t forget there's crabbing every day from our pontoon.&lt;/P&gt;</description>
      <image>
        <title>August 2011</title>
        <description>Summer Holiday Activities</description>
        <caption />
        <url>http://newsletters.falmouth.ac.uk/uploads/22c0a56b-f372-4569-ae8c-9e0b475115f8.jpg</url>
        <width>190</width>
        <height>100</height>
      </image>
      <pubDate>Tue, 16 Aug 2011 14:39:54 GMT</pubDate>
    </item>

    <item id="779">
      <title>Douglas Dapper - The Story Explorer 002</title>
      <link>http://www.nmmc.co.uk/newsletter/link.php?M=10940&amp;N=165&amp;L=248&amp;F=H</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Every Thursday until 1 September&lt;/STRONG&gt;&lt;BR&gt;Our Story Explorer will take you on a magical journey around the Museum to discover weird and wonderful tales from across the world.&amp;nbsp; Look out for pirates, polar bears and Packet ships throughout the summer.&lt;/P&gt;</description>
      <image>
        <title>August 2011</title>
        <description>Douglas Dapper - The Story Explorer</description>
        <caption />
        <url>http://newsletters.falmouth.ac.uk/uploads/ab01dbdf-d671-4127-9b9d-9aa6878bd97b.jpg</url>
        <width>190</width>
        <height>100</height>
      </image>
      <pubDate>Tue, 16 Aug 2011 10:58:12 GMT</pubDate>
    </item>

    <item id="780">
      <title>Two Castles Gig Race 003</title>
      <link>http://www.nmmc.co.uk/newsletter/link.php?M=10940&amp;N=165&amp;L=343&amp;F=H</link>
      <description>&lt;P&gt;&lt;STRONG&gt;7 August&lt;/STRONG&gt;&lt;BR&gt;Cheer on local pilot gig crews racing from St Anthony's Head to the Maritime Museum.&amp;nbsp; Watch on land from Events Square or get a ticket for the spectator boat to have a close up view on the water.&lt;/P&gt;</description>
      <image>
        <title>August 2011</title>
        <description>Two Castles Gig Race</description>
        <caption />
        <url>http://newsletters.falmouth.ac.uk/uploads/f0fe2730-a51f-4653-98d0-499ae8627635.jpg</url>
        <width>190</width>
        <height>100</height>
      </image>
      <pubDate>Tue, 16 Aug 2011 10:58:17 GMT</pubDate>
    </item>

    <item id="785">
      <title>Summer Holiday Activities 001</title>
      <link>http://www.nmmc.co.uk/newsletter/link.php?M=10940&amp;N=165&amp;L=248&amp;F=H</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Until 4 September&lt;/STRONG&gt;&lt;BR&gt;Our school holiday activities are well under way and there are lots more to come.&amp;nbsp; Every week has a different theme and every day there’s a new creative craft activity to try.&amp;nbsp; And don’t forget there's crabbing every day from our pontoon.&lt;/P&gt;</description>
      <image>
        <title>August 2011</title>
        <description>Summer Holiday Activities</description>
        <caption />
        <url>http://newsletters.falmouth.ac.uk/uploads/22c0a56b-f372-4569-ae8c-9e0b475115f8.jpg</url>
        <width>190</width>
        <height>100</height>
      </image>
      <pubDate>Tue, 16 Aug 2011 14:39:54 GMT</pubDate>
    </item>

    <item id="779">
      <title>Douglas Dapper - The Story Explorer 002</title>
      <link>http://www.nmmc.co.uk/newsletter/link.php?M=10940&amp;N=165&amp;L=248&amp;F=H</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Every Thursday until 1 September&lt;/STRONG&gt;&lt;BR&gt;Our Story Explorer will take you on a magical journey around the Museum to discover weird and wonderful tales from across the world.&amp;nbsp; Look out for pirates, polar bears and Packet ships throughout the summer.&lt;/P&gt;</description>
      <image>
        <title>August 2011</title>
        <description>Douglas Dapper - The Story Explorer</description>
        <caption />
        <url>http://newsletters.falmouth.ac.uk/uploads/ab01dbdf-d671-4127-9b9d-9aa6878bd97b.jpg</url>
        <width>190</width>
        <height>100</height>
      </image>
      <pubDate>Tue, 16 Aug 2011 10:58:12 GMT</pubDate>
    </item>

    <item id="780">
      <title>Two Castles Gig Race 003</title>
      <link>http://www.nmmc.co.uk/newsletter/link.php?M=10940&amp;N=165&amp;L=343&amp;F=H</link>
      <description>&lt;P&gt;&lt;STRONG&gt;7 August&lt;/STRONG&gt;&lt;BR&gt;Cheer on local pilot gig crews racing from St Anthony's Head to the Maritime Museum.&amp;nbsp; Watch on land from Events Square or get a ticket for the spectator boat to have a close up view on the water.&lt;/P&gt;</description>
      <image>
        <title>August 2011</title>
        <description>Two Castles Gig Race</description>
        <caption />
        <url>http://newsletters.falmouth.ac.uk/uploads/f0fe2730-a51f-4653-98d0-499ae8627635.jpg</url>
        <width>190</width>
        <height>100</height>
      </image>
      <pubDate>Tue, 16 Aug 2011 10:58:17 GMT</pubDate>
    </item>

  </channel>
</rss>

Did you try your own code? 您是否尝试过自己的代码? There's no reason you can't wrap tags in XSL conditions, as you have. 没有理由像您一样没有理由在XSL条件下包装标签。 Here's what I presume to be your intended result: 我想这是您预期的结果:

http://xmlplayground.com/9TXioN http://xmlplayground.com/9TXioN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM