3

I need to get the image source out of this code:

<content:encoded>
    <![CDATA[
        <span><img width="200" src="..."></span><br /> [some Text] ]]>
</content:encoded>

This is what I tried:

 <xsl:variable name="ImageURL" select="substring-before(substring-after(content, 'src=&quot;'), '&quot;&gt;')" />
 <img alt="" src="{$ImageURL}" width="75" height="49" />

Unfortunately my solutions failed. I also tried some other syntax but the main part was the same. Could anybody help me please?

Thanks for all effort!

1
  • <item> <title><![CDATA[ ... ]]></title> <link></link> <content:encoded> <![CDATA[ <span><img width="200" src="..."></span><br />]]> </content:encoded> <pubDate></pubDate> <category>feed_theme</category> <author></author> <guid> This is one feeditem what "namespace" do you mean? Or do you mean the feedURL? </guid> </item> Dec 13, 2012 at 21:22

2 Answers 2

2

Your xslt should be something like:

<xsl:variable name="ImageURL" xmlns:content="http://namespaceurl" select="substring-before(substring-after(content:encoded, 'src=&quot;'), '&quot;')" />
<img alt="" src="{$ImageURL}" width="75" height="49" />

Where http://namespaceurl matches the namespace "url" of content from the input

To find that namespace url look at the input xml it'll define the xmlns:content somewhere like this:

<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">

If this is how it's defined then http://purl.org/rss/1.0/modules/content/ is the namespace url and your xslst should contain:

<xsl:variable name="ImageURL" xmlns:content="http://purl.org/rss/1.0/modules/content/" select="substring-before(substring-after(content:encoded, 'src=&quot;'), '&quot;')" />
<img alt="" src="{$ImageURL}" width="75" height="49" />
1
  • Please look at my answer above. Dec 13, 2012 at 21:23
0

I have the same problem. But the namespaceurl looks different in my xml source. I have this one:

rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"

Then, follow the solution, I use:

<xsl:variable name="ImageURL" xmlns:atom="http://www.w3.org/2005/Atom"  select="substring-before(substring-after(atom:encoded, 'src=&quot;'), '&quot;')" />
<li>
   <img alt="" src="{$ImageURL}" width="60" height="60" />
</li>

But when I see the code for the web page, I have:

<li> 
  <img alt="" src="" width="60" height="60" />
</li>
1
  • Could you please provide us the sourcecode of your IMG-Tag you try to read out? Mar 25, 2013 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.