Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    Dec 14, 2010 @ 06:17
    syn-rg
    0

    StripHtml but keep the links

    I'm creating an FAQ page that is listing an "FAQ item" as a list of child nodes.

    The "FAQ item" has two RTE on it, one for the question, one for the answer. Reason being, my FAQ page is using jQuery to display the "Answer" when the "Question" is clicked. I thought of using StripHtml to get the content from the two seperate RTE's. But this, of course, strips any links I may have in the "Answer" RTE.

    Can anyone suggest a better method than what I'm currently using? I want to be able to keep my links from my "Answer" RTE.

    Here's my current code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:uTube.XSLT="urn:uTube.XSLT" xmlns:Designit.VideoEmbed="urn:Designit.VideoEmbed" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
      exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets uTube.XSLT Designit.VideoEmbed PS.XSLTsearch "
    >

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
      <div id="FAQs_list_container">
        <ul>
          <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
            <li>
              <h1 class="faq-question">
                <a href="#" name="{@nodeName}">
                  <xsl:value-of select="umbraco.library:StripHtml(./question)" />
                </a>
              </h1>
              <p class="faq-answer" id="{@nodeName}">
                <xsl:value-of select="umbraco.library:StripHtml(./answer)" />
              </p>
            </li>
          </xsl:for-each>
        </ul>
      </div>

    </xsl:template>

    </xsl:stylesheet>

    PS. This is not important, but I know I could use Textbox Multiple or Textstring for the "Question" field, but wanted the "Question" and "Answer" fields to look the same in the backend. Purely from an aesthetic point of view.

  • Rich Green 2246 posts 4008 karma points
    Dec 14, 2010 @ 06:25
    Rich Green
    0

    Hey JV,

    I'm not sure why you need to strip the HTML?

    You can just render the RTE field like this removing the first <p> tag so they are not nested

    <xsl:value-of select="umbraco.library:RemoveFirstParagraphTag(./answer)disable-output-escaping="yes"/>

    Rich

  • syn-rg 282 posts 425 karma points
    Dec 14, 2010 @ 06:47
    syn-rg
    0

    Hi Rich,

    I just need a method of displaying the content from the "Answer" RTE, with it's StripHtml or something else isn't important.

    I tried your suggestion, however it resulted in the following:

     "All external vacancies are advertised on our Currentcareer opportunities page." - Current career opportunities is supposed to be the link but as you can see it's not working correctly.

    <p id="FAQ-1" class="faq-answer" style="opacity: 1; display: block;">All external vacancies are advertised on our <ahref=" title="Training and development" training-and-development.aspx="" your-benefits="" careers="">Currentcareer opportunities page.</ahref="></p>

     

  • Rich Green 2246 posts 4008 karma points
    Dec 14, 2010 @ 06:59
    Rich Green
    0

    Hey JV,

    There's something else going on here, can you open up an answer node and click the RTE and view the html and post it here?

    Rich

  • syn-rg 282 posts 425 karma points
    Dec 14, 2010 @ 07:03
    syn-rg
    0
    <p>All external vacancies are advertised on our <a href="/{localLink:1543}" title="Training and development">Current career opportunities</a> page.</p>
  • Rich Green 2246 posts 4008 karma points
    Dec 14, 2010 @ 07:10
    Rich Green
    0

    Hey JV, 

    Your href attribute is empty? Try putting a hash in there <a href="#" title="Training and developement">Current</a>

    I'm a little confused about what you are trying to achieve, but possibly Tiny MCE (the RTE) is trying to 'fix' your empty href when you save.

    Rich

  • syn-rg 282 posts 425 karma points
    Dec 14, 2010 @ 07:17
    syn-rg
    0

    Sorry Rich,

    That's weird it wasn't when I posted it, I'll try it again:

    <p>All external vacancies are advertised on our <a href="/{localLink:1423}" title="Capabilities">Current career opportunities</a> page.</p>

  • Rich Green 2246 posts 4008 karma points
    Dec 14, 2010 @ 07:59
    Rich Green
    1

    What output do you get when you just try to output the rte with no striping of characters?

    <xsl:value-of select="./answerdisable-output-escaping="yes"/>

     

  • syn-rg 282 posts 425 karma points
    Dec 14, 2010 @ 23:20
    syn-rg
    0

    Succes! Thanks for your help Rich.

    I had to slightly alter the code wrapping that line from a <p> tag to a <div> tag. As the <p> tag was now redundant, because it is now pulling the <p> tag from the RTE.

    Here's my final code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:uTube.XSLT="urn:uTube.XSLT" xmlns:Designit.VideoEmbed="urn:Designit.VideoEmbed" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
      exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets uTube.XSLT Designit.VideoEmbed PS.XSLTsearch "
    >

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
      <div id="FAQs_list_container">
        <ul>
          <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
            <li>
              <h1 class="faq-question">
                <a href="#" name="{@nodeName}">
                  <xsl:value-of select="umbraco.library:StripHtml(./question)" />
                </a>
              </h1>
              <div class="faq-answer" id="{@nodeName}">
                <xsl:value-of select="./answer" disable-output-escaping="yes"/>
              </div>
            </li>
          </xsl:for-each>
        </ul>
      </div>

    </xsl:template>

    </xsl:stylesheet>
Please Sign in or register to post replies

Write your reply to:

Draft