xsl-list
[Top] [All Lists]

Re: AW: [xsl] RSS 2.0 to RSS 1.0 XSLT problem in Luminis 3.3

2006-07-12 09:42:04
Roman,

Thanks for the corrections, I appreciate the help immensely.

Here are two feeds from the same source so the XSLT can be checked for accuracy:

Music For Robots (a great music site with downloadable MP3s, BTW)
RSS 1.0 - http://music.for-robots.com/index.rdf 
RSS 2.0 - http://music.for-robots.com/index.xml 

I'm trying to make this as general purpose as possible so that it can provide 
at least minimal transformation on any RSS 2.0 feed.  That's why I'm not 
including optional items or other namespaces.  Of course it could be extended 
to be more robust, but I was just trying to get it to work first.

I meant to leave the items out of the channel template like that because of the 
differences between RSS 2.0 and 1.0.  In 2.0, everything is included in the 
<channel> tag, but in 1.0 <channel> is more like a header block, with each 
<item> being listed separately.  Have a look at the example files and you'll 
see what I mean.

Again, thanks for the help!

Cheers,
Seth


Roman(_dot_)Huditsch(_at_)lexisnexis(_dot_)at 7/12/2006 12:21 PM >>>
Hi Seth,

You are getting transformation, because you are mixing up the XSL
instructions (although the error message seems a bit odd).

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

You need to declare the namespace for the rdf prefix in your
<xsl:stylesheet>, too, since you need it in nearly all of your
templates. 

<xsl:template match="rss">
<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  xmlns="http://purl.org/rss/1.0/";>

  <xsl:template match="channel">
    <channel>
      <xsl:attribute name="rdf:about"><xsl:value-of
select="link"/></xsl:attribute>
      <title><xsl:value-of select="title"/></title>
      <description><xsl:value-of select="description"/></description>
      <image><xsl:attribute name="rdf:resource"><xsl:value-of
select="image"/></xsl:attribute></image>
    <items><rdf:Seq>
        <xsl:for-each select="item">
          <rdf:li>
                <xsl:attribute name="rdf:resource"><xsl:value-of
select="link"/></xsl:attribute>
              </rdf:li>
        </xsl:for-each>
      </rdf:Seq></items>
    <textinput><xsl:value-of select="textinput"/></textinput>
    </channel>
  </xsl:template>

Templates can't be nested in XSLT. If you want to apply templates for
other nodes in an template, use <xsl:apply-templates> instead.
<xsl:template> must be a child element of <xsl:stylesheet>.

  <xsl:transform match="channel/image">
    <image>
      <xsl:attribute name="rdf:resource"><xsl:value-of
select="url"/></xsl:attribute>
        <title><xsl:value-of select="image/title"/></title>
        <url><xsl:value-of select="image/url"/></url>
        <link><xsl:value-of select="image/link"/></link>
    </image>
  </xsl:transform>

<xsl:transform> is a synonym for <xsl:stylesheet> and therefore
completely wrong here. You need to change this to be an <xsl:template
...> and move it one level up in your hierarchy. You should also include
an <xsl:apply-template> in your stylesheet invoking this template...

  <xsl:for-each select="channel/item">
    <item>
        <xsl:attribute name="rdf:about"><xsl:value-of
select="link"/></xsl:attribute>
        <title><xsl:value-of select="title"/></title>
        <link><xsl:value-of select="link"/></link>
        <description><xsl:value-of
select="description"/></description>
      </item>
  </xsl:for-each>

I think you should better include this part somewhere in your channel
template...

  <xsl:transform match="channel/textinput">
    <textinput>
        <xsl:attribute name="rdf:about"><xsl:value-of
select="url"/></xsl:attribute>
        <title><xsl:value-of select="title"/></title>
        <description><xsl:value-of
select="description"/></description>
        <link><xsl:value-of select="link"/></link>
    </textinput>
  </xsl:transform>

This template needs to be under <xsl:stylesheet> as well.

</rdf:RDF>
</xsl:template>

</xsl:stylesheet>

If your source document uses a namespace, you need to take that into
account, too.
I didn't have an appropriate RSS 2.0 document at hand, so I can't give
you more detailed information. If you could provide a simple input
document, I can give you an XSLT doing the job.

I hope this helps.

best regards,
Roman

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list 
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/ 
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>