I am using Umbraco and I need to display an image in a Rss Feed. The feed is generated by Xslt.
Everything works if I do text stuff. Such stuff is technically feasible, but the feed I analyzed had been generated by WordPress.
The challenge is that I have no idea how I can embed within my tag.
I have a variable, say “url”, that returns the full url of the underlying image. How can I insert within ? Remember I am using Xslt to achieve the task.
<content:encoded>
<img src="{$url}" />
</content:encoded>
I guess that CDATA must be used, but I am not able to escape correctly illegal characters 🙁
Thanks for your help.
Roland
roland, you’re trying to escape things twice. It’s unnecessary (not to mention hideous!) This page shows:
I.e. they’re just escaping the markup inside the
<content:encoded>once, and they use CDATA to do that. In your case, CDATA is awkward because you need to substitute $url in the middle. So you could use two CDATA sections wrapped around an<xsl:value-of select="$url" />: (indented for clarity)But that would be needlessly verbose. The second CDATA section is unneeded. And we can do better while using the same principle: escape the markup characters (once) that would cause the string to be parsed into a tree. In your case, only the initial
<needs to be escaped. You can use<instead of CDATA to escape the<. Put this in your XSLT:The
<xsl:value-of>is not really inside quotes, from XSLT’s perspective… those quotes are just the content of text nodes. The<xsl:value-of>works as a normal XSLT instruction.Change
select='$url'toselect="concat($siteUrl, photo)"if that’s what you need. (I.e. photo is a child element of the context node, and its text value is the name of the image file.)