Copied to clipboard

Flag this post as spam?

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


  • Andrew Blackmore 84 posts 127 karma points
    Feb 24, 2010 @ 16:40
    Andrew Blackmore
    0

    Appending HTML to the end of a string

    Hi all,

     

    This is something I can do no problem in a template because I can just use an insertTextAfter attribute but I need this done in a macro.

     

    I have the XSLT pulling out the first paragraph of text from an entry using the following code

     <xsl:value-of select="substring-before($post/data [@alias = 'bodyText'],'&lt;/p')" disable-output-escaping="yes"/>

    It works perfectly except it does not close the paragraph tag so it throws alot of my alignment off and makes my code not validate.

    I think I'm missing something simple in XSLT.

    Any ideas?

  • Neil Fenwick 86 posts 63 karma points
    Feb 24, 2010 @ 16:53
    Neil Fenwick
    0

    Andrew,

    Just in case... can you just put the paragraph tags around your xsl:value-of statement?

    e.g.

    <p><xsl:value-of select="$post/data [@alias = 'bodyText']" disable-output-escaping="yes"/></p>

    That would still be valid xml / xslt

  • Neil Fenwick 86 posts 63 karma points
    Feb 24, 2010 @ 16:57
    Neil Fenwick
    0

    Sorry Ignore my previous post - I misread - just understood what you were trying to do...

    I haven't tested this out and I'm not sure how well the umbraco.library:StripHtml function will work with unclosed tags:

     

    <xsl:value-of select="umbraco.library:StripHtml(substring-before($post/data [@alias = 'bodyText'],'&lt;/p'))" disable-output-escaping="yes"/>
  • Neil Fenwick 86 posts 63 karma points
    Feb 24, 2010 @ 17:04
    Neil Fenwick
    100

    One more last option:

    umbraco.library:RemoveFirstParagraphTag

    <xsl:value-of select="umbraco.library:RemoveFirstParagraphTag(substring-before($post/data [@alias = 'bodyText'],'&lt;/p'))" disable-output-escaping="yes"/>
  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 24, 2010 @ 17:17
    Dirk De Grave
    0

    i think the substring-before only gets part of the string before the actual p tag, and p tag not included? If so, use concat() xslt function to concat the first part (using substring-before) and the closing p tag.

    Does that help

     

    Cheers,

    /Dirk

     

  • Andrew Blackmore 84 posts 127 karma points
    Feb 24, 2010 @ 17:40
    Andrew Blackmore
    0

    Hi Everyone,

     

    Thanks for such a fast response. Dirk, you are right that the p end tag is not included and concat may be a good way to go but Neil's second response did the trick in the easiest way.

              <p>
                <xsl:value-of select="umbraco.library:RemoveFirstParagraphTag(substring-before($post/data [@alias = 'bodyText'],'&lt;/p'))" disable-output-escaping="yes"/>
              </p>

    Neil, the first answer didn't work out because it strips out any text formatting but the second option works like a charge. Just surrounded that with p tags like so

     

    and it works perfectly.

     

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft