XSLT

2011-02-09 10 views
0

にループ私は(現在のケースでは、カウントは2であるのです)、次のXMLXSLT

<?xml version="1.0" encoding="utf-8"?> 
<?xml-stylesheet href="sample.xsl" type="text/xsl"?> 
<rss version="2.0" 
xmlns:atom="http://www.w3.org/2005/Atom" 
xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" 
xmlns:dc="http://purl.org/dc/elements/1.1/"> 
    <channel 
    xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal"> 
     <title cf:type="text">The Hindu - Front Page</title> 
     <link>http://www.hindu.com/</link> 
     <description cf:type="text">The Internet edition of The Hindu, 
      India's national newspaper</description> 
     <image> 
      <url>http://www.hindu.com/hindu/hindux.gif</url> 
      <title>hindu.com</title> 
      <link>http://www.hindu.com/</link> 
     </image> 
     <item> 
      <title cf:type="text" 
      xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" 
      >ISRO spectrum deal under review: Centre</title> 
     </item> 
     <item> 
      <title cf:type="text" 
      xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" 
      >Response from Devas</title> 
     </item> 
    </channel> 
</rss> 

RSS /チャネル/項目は、任意の数のものとすることができる持っています。私は検討

ISROスペクトルの契約を次のように他の後マーキー一つとしてタイトルを表示する必要があります:センター、四天王からの応答は、....、....私はこれを実現するにはどうすればよい

XSLT?親切にアドバイスあなたのサンプルに対して

おかげ

答えて

2
<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:cfi="http://www.microsoft.com/schemas/rss/core/2005/internal" 
    xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" 
    xmlns:dc="http://purl.org/dc/elements/1.1/" 
    exclude-result-prefixes="cfi cf dc"> 
    <xsl:output method="html" indent="yes"/> 

    <xsl:template match="/*"> 
     <div id="marquee"> 
      <xsl:apply-templates select="channel/item/title"/> 
     </div> 
    </xsl:template> 

    <xsl:template match="title"> 
     <xsl:value-of select="."/> 
     <xsl:if test="not(position() = last())">, </xsl:if> 
    </xsl:template> 

</xsl:stylesheet> 

結果:正しい答えを@Flackに加えて

<div id="marquee">ISRO spectrum deal under review: Centre, Response from Devas</div> 
+0

クールを....これはあなたの助けに感謝トンに動作します。ところで、XSLの良い本をお勧めしますか? – padLing

+0

@padLingの場合、答えを受け入れる必要があります(私の答えの左上にあるチェックマークをクリックしてください)。 – Flack

+0

@padLing、書籍については、この質問を確認してください:http://stackoverflow.com/questions/339930/any-good-xslt-tutorial-book-blog-site-online – Flack

1

、XSLT 2.0 xsl:value-of命令シーケンスを保持します。だから、このスタイルシート:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
     <div id="marquee"> 
      <xsl:value-of select="rss/channel/item/title" 
          separator=", "/> 
     </div> 
    </xsl:template> 
</xsl:stylesheet> 

はまた出力:

<div id="marquee" 
>ISRO spectrum deal under review: Centre, Response from Devas</div> 
+0

+1 - 私はそれを実装したにもかかわらずセパレータについて知りませんでした! –