Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brian Juul Andersen 44 posts 98 karma points c-trib
    Nov 26, 2012 @ 11:24
    Brian Juul Andersen
    0

    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..

    <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.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Nov 26, 2012 @ 11:35
    Chriztian Steinmeier
    0

    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 

  • Brian Juul Andersen 44 posts 98 karma points c-trib
    Nov 26, 2012 @ 12:03
    Brian Juul Andersen
    0

    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

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Nov 26, 2012 @ 12:13
    Chriztian Steinmeier
    1

    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

  • Brian Juul Andersen 44 posts 98 karma points c-trib
    Nov 26, 2012 @ 12:32
    Brian Juul Andersen
    0

    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

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Nov 26, 2012 @ 13:30
    Lee Kelleher
    0

    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?

    .content p img {display:none;}

    Cheers, Lee.

  • Brian Juul Andersen 44 posts 98 karma points c-trib
    Nov 26, 2012 @ 15:27
    Brian Juul Andersen
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft