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

        <span><img width="200" src="..."></span><br /> [some Text] ]]>

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!

  • <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> – Felix Zeidler Dec 13 '12 at 21:22

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" />
|improve this answer|||||
  • Please look at my answer above. – Felix Zeidler Dec 13 '12 at 21:23

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;')" />
   <img alt="" src="{$ImageURL}" width="60" height="60" />

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

  <img alt="" src="" width="60" height="60" />
|improve this answer|||||
  • Could you please provide us the sourcecode of your IMG-Tag you try to read out? – Felix Zeidler Mar 25 '13 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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