I got some content from the editor which may or may not contain an image element. What I want to do is remove or omit this image element from rendering.
How do I go about doing that with XSLT ?
I have been looking into making a matching template.. something in the lines of..
<xsl:template match="img">
<!-- some magic happens -->
</xsl:template>
.. but I can´t get it to work :(
Any hints or pointers in the right direction are appreciated.
If this is in the RichText Editor, you'll have to either do some string-manipulation, or better yet - convert it to XML so you can use the "right" approach (using match templates etc.).
I wrote an article about the second one here - it's a little advanced because we have to run through a couple of hoops (Umbraco stores the Rich Text Editor's content as a string in the XML) at first, but after that you can use the magic you mention yourself :-)
Yes it is the RichText Editor.. sry .. I should have been more clear on that.
Thank you for pointing me to your article. I just read it and it seems that is what I would like to do. How ever .. is it really necessary to install uComponents for this to work / is there another way around it ? (XSLTouch seems to be there only for convenience I guess ?)
If you're not using any of the gazillion other major cool things in uComponents, you could probably write an App_Code extension for doing the same thing - and then use that in your XSLT. It's just that the one uComponents already handles some common edge cases already...
XSLTouch is for convenience, yes - but trust me; If you're using xsl:include more than once or twice you will have atleast one of those embarrasing "Why the f*** doesn't it load my changes???" moments :-)
It seems like a bit of an over kill just to remove an image. Furthermore I´m hacking on a live site (several domains on the server) and I´m not the guy that wants to take them all down by experimenting. Also we are at the limit of my skills here I guess...hmm .. I think I will have to rethink this.
Thank you very much for your inputs anyway Chriztian !
Remove IMG element from content
Situation:
I got some content from the editor which may or may not contain an image element. What I want to do is remove or omit this image element from rendering.
How do I go about doing that with XSLT ?
I have been looking into making a matching template.. something in the lines of..
.. but I can´t get it to work :(
Any hints or pointers in the right direction are appreciated.
Hi Brian,
If this is in the RichText Editor, you'll have to either do some string-manipulation, or better yet - convert it to XML so you can use the "right" approach (using match templates etc.).
I wrote an article about the second one here - it's a little advanced because we have to run through a couple of hoops (Umbraco stores the Rich Text Editor's content as a string in the XML) at first, but after that you can use the magic you mention yourself :-)
/Chriztian
Hi Criztian,
Yes it is the RichText Editor.. sry .. I should have been more clear on that.
Thank you for pointing me to your article. I just read it and it seems that is what I would like to do. How ever .. is it really necessary to install uComponents for this to work / is there another way around it ? (XSLTouch seems to be there only for convenience I guess ?)
---Brian
Well,
If you're not using any of the gazillion other major cool things in uComponents, you could probably write an App_Code extension for doing the same thing - and then use that in your XSLT. It's just that the one uComponents already handles some common edge cases already...
XSLTouch is for convenience, yes - but trust me; If you're using xsl:include more than once or twice you will have atleast one of those embarrasing "Why the f*** doesn't it load my changes???" moments :-)
/Chriztian
It seems like a bit of an over kill just to remove an image. Furthermore I´m hacking on a live site (several domains on the server) and I´m not the guy that wants to take them all down by experimenting. Also we are at the limit of my skills here I guess...hmm .. I think I will have to rethink this.
Thank you very much for your inputs anyway Chriztian !
---Brian
Hi Brian,
I got a bit scared for you when I read "I'm hacking on a live site" ... Good luck! Make lots of regular backups!
Do you really need to remove the <img> tag from the mark-up? If it is a visual issue, could you use CSS to hide it?
Cheers, Lee.
Hi Lee,
I have had that solution in mind ("removing" it through CSS) but decided to try getting rid of it with some XSLT for two reasons:
1) It seems to be to proper way to do it. And the CMS being Umbraco - it should be possible ;)
2) It would be good training for me. I still lack a bit in XSLT skills I think ;)
---Brian
is working on a reply...