Jump to content

Why is xsltproc and my XSL stopping at first entry?

Dan_Linder's Photo
Posted Feb 01 2010 09:03 PM
2409 Views

I'm trying to query MP3 album/title/filename from an RSS feed using this XSL:
<?xml version="1.0"?>
<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
  <output method="text"/>
  <template match="/" >
ALBUM="<value-of select="/rss/channel/title"/>"
TITLE="<value-of select="/rss/channel/item/title"/>"
FILE="<value-of select="/rss/channel/item/enclosure/@url"/>"
  </template>
</stylesheet>


But when I save it as parse.xsl and run it like this:
xsltproc parse.xsl http://www.npr.org/rss/podcast.php?id=510221


It only prints the first RSS entry:
ALBUM="NPR: Science Friday Podcast"
TITLE="Sean Carroll On The Mysteries Of Time"
FILE="http://podcastdownload.npr.org/anon.npr-podcasts/podcast/510221/123138876/npr_123138876.mp3"



What else am I missing?

Tags:
0 Subscribe


2 Replies

0
  cutlass2003's Photo
Posted Feb 01 2010 09:54 PM

you are getting only a single result because your <template match="/" > is specified to match the top root level node ... of which there is only one. You will need to change the xpath to match each item element.

there are plenty of examples of using XSLT to process RSS online, here is one example which you may find useful

http://www.pheed.com...SLTexample.html
0
  Infant Programmer's Photo
Posted Feb 04 2010 10:42 PM

I can't see XML file or hierarchy of your xml nodes :unsure: .. so let me assume your input xml .. something like this:
<root>
  <data>
    <album>name1</album>
    <title>title1</title>
    <file>location1</file>
  </data>
  <data>
    <album>name2</album>
    <title>title2</title>
    <file>location2</file>
  </data>
  <data>
    <album>name3</album>
    <title>title3</title>
    <file>location3</file>
  </data>
</root>



So you want to parse through each <data/> node and get the data ..
This would be the XSL to list out each album name, title and the corresponding location ..

<xsl:template match="root">
    <xsl:for-each select="data">
      <xsl:text>    Details : </xsl:text>
      <xsl:text>album name:</xsl:text>
      <xsl:value-of select="album"/>
      <xsl:text>, title:</xsl:text>
      <xsl:value-of select="title"/>
      <xsl:text>, location:</xsl:text>
      <xsl:value-of select="file"/>
    </xsl:for-each>
  </xsl:template>



Hope it helped .. :)
Infant Pro,
India.