将前 30 个 RSS 元素转换为 xsl 文件

Transform first 30 RSS elements into xsl file

我正在学习 XML 课程,我们必须在该课程中创建多面分类系统。作业的第一步是将 RSS 文件中的前 30 个项目放入 xsl 转换中。

我的困惑来自如何从这个 RSS 文件中获取前 30 个项目:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Recipezaar: Newest recipes</title>
    <link>http://www.recipezaar.com</link>
    <description>The newest recipes on Recipezaar</description>
    <copyright>Copyright 2009 Recipezaar</copyright>
    <managingEditor>editor@recipezaar.com</managingEditor>
    <webMaster>support@recipezaar.com</webMaster>
    <pubDate>Tue, 17 Nov 2009 15:51:16 -0500</pubDate>
    <lastBuildDate>Tue, 17 Nov 2009 15:51:16 -0500</lastBuildDate>
    <language>en-us</language>
    <ttl>1440</ttl>
    <rating>(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true for
      "http://www.recipezaar.com" r (cz 1 lz 1 nz 1 oz 1 vz 1)
      "http://www.rsac.org/ratingsv01.html" l gen true for
      "http://www.recipezaar.com" r (n 0 s 0 v 0 l 0))</rating>
    <item>
      <title>Cunetto's Chicken Spedini</title>
      <link>http://www.recipezaar.com/399780</link>
      <description>I LOVE Cunetto's House of Pasta. I found this recipe at
        recipegoldmine.com. I havent tried it yet. Cooking time includes
        marinating time. -- posted by &lt;a
        href="http://www.recipezaar.com/member/572672"&gt;jrivera&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399780</guid>
      <pubDate>Tue, 17 Nov 2009 00:55:37 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Ginger Broth</title>
      <link>http://www.recipezaar.com/399781</link>
      <description>A variation on a soup that is on this website, only this one
        is for those days when you need a flavoring, or are too sick to have
        solids! Vary tasty though, and roommate approved ;) -- posted by
        &lt;a href="http://www.recipezaar.com/member/1298866"&gt;More
        Gun&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399781</guid>
      <pubDate>Tue, 17 Nov 2009 00:57:11 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Spiced Carrot and Lentil Soup</title>
      <link>http://www.recipezaar.com/399782</link>
      <description>This combination of carrots and lentils is so tasty and the
        spices give just a hint of zing to this delicious thick
        &amp;quot;stick to your ribs&amp;quot; Soup Its so easy to make
        and freezes well -- posted by &lt;a
        href="http://www.recipezaar.com/member/233780"&gt;JoyfulCook&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399782</guid>
      <pubDate>Tue, 17 Nov 2009 00:57:32 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Hot Spiced Tea</title>
      <link>http://www.recipezaar.com/399783</link>
      <description>I found this on a Splenda coupon. I have not tried this
        recipe, but I'm posting this for safe keeping. -- posted by &lt;a
        href="http://www.recipezaar.com/member/57042"&gt;internetnut&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399783</guid>
      <pubDate>Tue, 17 Nov 2009 00:58:03 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Spicy Banana Bars</title>
      <link>http://www.recipezaar.com/399784</link>
      <description>Senior Prize Winner in Pillsbury's 6th Grand National Recipe
        and Baking Contest by Mrs. Byard Cummings, Enderlin, North Dakota. I
        found this in a old Pillsbury magazine. I have not tried this recipe,
        but I'm posting it for safe keeping. -- posted by &lt;a
        href="http://www.recipezaar.com/member/57042"&gt;internetnut&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399784</guid>
      <pubDate>Tue, 17 Nov 2009 00:58:53 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>The Best King Ranch Chicken Ever</title>
      <link>http://www.recipezaar.com/399785</link>
      <description>My moms recipe that our entire family loves. Great when it's
        cold outside. -- posted by &lt;a
        href="http://www.recipezaar.com/member/1444095"&gt;Cookingbaby&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399785</guid>
      <pubDate>Tue, 17 Nov 2009 00:59:20 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Sloppy Joe's on Corn Bread</title>
      <link>http://www.recipezaar.com/399786</link>
      <description>It says this recipe cost .64 cents per serving. I found this
        recipe in Family Circle magazine. I have not tried this recipe, but I'm
        posting it for safe keeping. -- posted by &lt;a
        href="http://www.recipezaar.com/member/57042"&gt;internetnut&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399786</guid>
      <pubDate>Tue, 17 Nov 2009 01:01:25 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Chicken Asado</title>
      <link>http://www.recipezaar.com/399787</link>
      <description>Nothing like chicken soaked in red sauce over potatoes!!!
        This is a major comfort food for me. I serve this over-top of potatoes
        and I am in heaven!! -- posted by &lt;a
        href="http://www.recipezaar.com/member/692048"&gt;two happy
        children&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399787</guid>
      <pubDate>Tue, 17 Nov 2009 01:01:47 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Uncle Charlie's Corn Bread</title>
      <link>http://www.recipezaar.com/399788</link>
      <description>It says it cost .18 cents for each serving. I found this in
        Family Circle magazine. I have not tried this recipe, but I'm posting it
        for safe keeping. -- posted by &lt;a
        href="http://www.recipezaar.com/member/57042"&gt;internetnut&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399788</guid>
      <pubDate>Tue, 17 Nov 2009 01:01:37 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Annie's Cheesy Wild Rice Soup</title>
      <link>http://www.recipezaar.com/399789</link>
      <description>Compliments of Annie Hartman of Medford WI -- posted by
        &lt;a
        href="http://www.recipezaar.com/member/363055"&gt;55tbird&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399789</guid>
      <pubDate>Tue, 17 Nov 2009 01:01:58 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Grandma's Cheesy Broccoli &amp;amp; Chicken Casserole</title>
      <link>http://www.recipezaar.com/399790</link>
      <description>This is down home comfort food at it's finest. It was the
        only way my grams could get me to eat my broccoli while growing up.
        These days I use brown rice for a lower carb, healthier version.
        Sometimes I also use chicken thigh instead of breast because it's so
        much more tender. I hope you love it was much as I do. -- posted by
        &lt;a href="http://www.recipezaar.com/member/202325"&gt;Bitter
        Moon&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399790</guid>
      <pubDate>Tue, 17 Nov 2009 01:02:04 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Maple Nog</title>
      <link>http://www.recipezaar.com/399791</link>
      <description>A soothing cup of creamy maple nog is the perfect
        accompaniment to a good book and a crackling fire. Each serving is
        6-ounces. I found this recipe at a Estate sale. I have not tried this
        recipe, but I'm posting it for safe keeping. I plan to use sugar free
        maple pancake syrup. -- posted by &lt;a
        href="http://www.recipezaar.com/member/57042"&gt;internetnut&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399791</guid>
      <pubDate>Tue, 17 Nov 2009 01:02:06 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Chicken Bolognese</title>
      <link>http://www.recipezaar.com/399792</link>
      <description>I found this recipe in Good House Keeping magazine. I have
        not tried this recipe, but I'm posting this for safe keeping. -- posted
        by &lt;a
        href="http://www.recipezaar.com/member/57042"&gt;internetnut&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399792</guid>
      <pubDate>Tue, 17 Nov 2009 01:03:35 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Sexy Chocolate Russian</title>
      <link>http://www.recipezaar.com/399793</link>
      <description>A little twist on the original chocolate Russian recipe, the
        twist? A hint of Alaska *waves* HIYA OVER THERE! Overall a strong smooth
        drink, even those who dislike strong drinks havedowned this one quick :D
        -- posted by &lt;a
        href="http://www.recipezaar.com/member/1298866"&gt;More
        Gun&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399793</guid>
      <pubDate>Tue, 17 Nov 2009 01:04:09 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Cream of Parsnip Soup With Crisp-Fried Pancetta</title>
      <link>http://www.recipezaar.com/399794</link>
      <description>from the LA Times For vegetarians, you can substitute
        crisp-fried shallots: slice shallots thinly, dust them lightly with
        flour and then deep-fry them until they are crisp, 3 to 5 minutes. Do
        not let them scorch. Season with salt before serving. -- posted by
        &lt;a href="http://www.recipezaar.com/member/372895"&gt;Karen in
        OC&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399794</guid>
      <pubDate>Tue, 17 Nov 2009 01:04:25 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Spicy Mac N Cheese</title>
      <link>http://www.recipezaar.com/399795</link>
      <description>A three cheese mac with a little kick! -- posted by &lt;a
        href="http://www.recipezaar.com/member/1207515"&gt;Sarahdoo10&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399795</guid>
      <pubDate>Tue, 17 Nov 2009 01:04:36 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Pan Fried Tilapia from Sandra Lee</title>
      <link>http://www.recipezaar.com/399796</link>
      <description>Easy and Money Saving way to pan fry tilapia from Food
        Network's Sandra Lee -- posted by &lt;a
        href="http://www.recipezaar.com/member/1207515"&gt;Sarahdoo10&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399796</guid>
      <pubDate>Tue, 17 Nov 2009 01:04:48 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Libby's Pumpkin Roll</title>
      <link>http://www.recipezaar.com/399797</link>
      <description>This recipe came from the label of Libby's 100% Pure Pumpkin
        -- posted by &lt;a
        href="http://www.recipezaar.com/member/1449931"&gt;Chef
        #1449931&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399797</guid>
      <pubDate>Tue, 17 Nov 2009 01:05:50 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Butternut Squash Bake</title>
      <link>http://www.recipezaar.com/399798</link>
      <description>Butternut Squash -- posted by &lt;a
        href="http://www.recipezaar.com/member/1074341"&gt;Chef
        #1074341&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399798</guid>
      <pubDate>Tue, 17 Nov 2009 01:05:56 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Spicy Maple Hot Sauce</title>
      <link>http://www.recipezaar.com/399799</link>
      <description>Very Spicy Pepper Sauce with a little bit of Sweetness. Sauce
        may not taste very spicy when it first comes off the stove, it gets more
        spicy with time. Let it sit a few days before using to allow flavours to
        blend efficiently, But CAN be used right away. -- posted by &lt;a
        href="http://www.recipezaar.com/member/565305"&gt;Chef
        #565305&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399799</guid>
      <pubDate>Tue, 17 Nov 2009 01:05:46 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Ali's Real Crab Crab Dip (Hot or Cold)</title>
      <link>http://www.recipezaar.com/399800</link>
      <description>This is a slightly spicy crab dip. May be served hot or cold.
        To be served with toasted with ciabatta bread. YUM! I created this
        recipe after eating a crab dip sandwich (ciabatta bread, swiss cheese
        and crab dip) at The Marina Cafe in Jacksonville, NC. -- posted by
        &lt;a href="http://www.recipezaar.com/member/1449931"&gt;Chef
        #1449931&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399800</guid>
      <pubDate>Tue, 17 Nov 2009 01:06:18 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Plain Pizza Base</title>
      <link>http://www.recipezaar.com/399801</link>
      <description>Plain pizza base made from scratch. It's easy and non messy.
        I like to prepare this for kids pizza party as it is easy to roll and
        makes about nine small thin-crust pizzas. You can roll it thick and make
        about four 9&amp;quot; pizzas. -- posted by &lt;a
        href="http://www.recipezaar.com/member/371693"&gt;evnn&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399801</guid>
      <pubDate>Tue, 17 Nov 2009 01:07:23 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Kani Salad (Imitation Crab Salad)</title>
      <link>http://www.recipezaar.com/399802</link>
      <description>I love this salad because it's not really a salad and it has
        one of my favorite foods, Kani! Kani is a Japanese sushi item, also
        called imitation crab and crab stick. This dish is great at parties. --
        posted by &lt;a
        href="http://www.recipezaar.com/member/1449273"&gt;Nicola
        Kwan&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399802</guid>
      <pubDate>Tue, 17 Nov 2009 01:07:13 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Triple Citrus Poppy Seed Cupcakes</title>
      <link>http://www.recipezaar.com/399803</link>
      <description>Recipe is from the Spice Islands website. -- posted by
        &lt;a
        href="http://www.recipezaar.com/member/118840"&gt;SweetJezebel&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399803</guid>
      <pubDate>Tue, 17 Nov 2009 01:07:39 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Nuts on the Rocks! or Walnut Martini</title>
      <link>http://www.recipezaar.com/399804</link>
      <description>This is so Nutty yummy. -- posted by &lt;a
        href="http://www.recipezaar.com/member/58104"&gt;~Rita~&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399804</guid>
      <pubDate>Tue, 17 Nov 2009 01:08:19 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Simple Cheesecake</title>
      <link>http://www.recipezaar.com/399805</link>
      <description>Cheese cake made as simple as possible -- posted by &lt;a
        href="http://www.recipezaar.com/member/1448755"&gt;Chef
        #1448755&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399805</guid>
      <pubDate>Tue, 17 Nov 2009 01:09:09 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Sooji Halwa (Low Fat/Sugar Version)</title>
      <link>http://www.recipezaar.com/399806</link>
      <description>This is a lower fat / lower sugar version of Sooji Halwa --
        posted by &lt;a
        href="http://www.recipezaar.com/member/745046"&gt;Chef
        #745046&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399806</guid>
      <pubDate>Tue, 17 Nov 2009 01:09:41 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Stuffed Chicken Breasts With Apple Cider Vinegar Sauce</title>
      <link>http://www.recipezaar.com/399807</link>
      <description>This is a much altered version of a recipe I found online a
        few years ago. I simplified it and it actually tastes better than the
        more difficult version. My family loves this recipe. My husband
        literally drinks the sauce. These are great for 4 or for 24. Very easy
        to scale up for large dinner parties. -- posted by &lt;a
        href="http://www.recipezaar.com/member/1438202"&gt;foodandwinelover&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399807</guid>
      <pubDate>Tue, 17 Nov 2009 01:11:04 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Pesto Feta Burger</title>
      <link>http://www.recipezaar.com/399808</link>
      <description>Delicious burger made with Pesto and Feta cheese. -- posted
        by &lt;a href="http://www.recipezaar.com/member/1450381"&gt;Koch
        Kevin&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399808</guid>
      <pubDate>Tue, 17 Nov 2009 01:11:26 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>
    <item>
      <title>Rob's Mango and Chilli Chutney</title>
      <link>http://www.recipezaar.com/399809</link>
      <description>Adding 1 of the mangoes at the end, means that this chutney
        retains a superb fresh flavour. Can be left in the fridge for 1 month or
        preserved and canned for over 1 year (follow the canning notes link on
        home page) Lovely with Indian or Mexican food or to enhance a cooked
        meat and cheese platter. Add a spoonful to curries or mix with cold
        shredded chicken, curry powder and mayonnaise for a lovely baked potato
        or sandwich filling. Just make sure your mangoes are really ripe and
        soft. -- posted by &lt;a
        href="http://www.recipezaar.com/member/1431918"&gt;robd16&lt;/a&gt;</description>
      <guid isPermaLink="true">http://www.recipezaar.com/399809</guid>
      <pubDate>Tue, 17 Nov 2009 01:12:44 -0500</pubDate>
      <source url="http://www.recipezaar.com">Recipezaar.com</source>
    </item>

然后将它们放入 XSL 转换中以重新创建此类输出,实际上我正在将此 RSS 文件转换为 XSL 文件

how would I be able to take the first 30 items from this RSS file

你可以这样做:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/rss">
    <yourRoot>
        <xsl:apply-templates select="channel/item[position() &lt;= 30]" />
    </yourRoot>
</xsl:template>

<xsl:template match="item">
    <!-- your code for processing an item -->
</xsl:template>

</xsl:stylesheet>