Copied to clipboard

Flag this post as spam?

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


  • Ol 7 posts 27 karma points
    Dec 07, 2010 @ 13:08
    Ol
    0

    How to output content from richtext editor using xslt?

    Hi all,

    Let me describe what I have and what I want to do.

    I have some pages (articles):

    "Codegarden 09" and "CWS2 is released"

    Each of them are the same document type with "Content" tab in Generic properties:

    At Content section it looks like this:

    So I have fields:

    - "News description" with alias "newsdescription" and type "Textbox multiple"

    - "News text" with alias "newstext" and type "Richtext editor"

    I want to out put content of this two fields on a new page. I use for this macro/xslt:

    <?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"
    exclude-result-prefixes="msxml umbraco.library">

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

      <xsl:param name="currentPage"/>

      <xsl:variable name="itemsToDisplay" select="30" />

      <xsl:template match="/">

        <xsl:choose>
          <xsl:when test="$currentPage/@id=2878">
    <!-- ***************************** Display events for 'EVENTS' page ********************************************************-->    
              <ul style="list-style-type:none;">
                <xsl:for-each select="$currentPage/ancestor-or-self::node/node [@id = '2886']/node">
              <xsl:sort select="data [@alias = 'date']" order="descending"/>
                    <xsl:if test="position() &lt;= $itemsToDisplay">
                      <li style="margin-bottom:6px;">
                            <xsl:value-of select="umbraco.library:FormatDateTime(data [@alias = 'date'], 'dd&#8260;MM&#8260;yyyy')"/><br />
                            <b><xsl:value-of select="data [@alias = 'newsheader']"/></b>
                <p>Parameter &#34;newsdescription&#34;:&nbsp;<xsl:value-of select="data [@alias = 'newsdescription']"/><br /><br />
                <p>Parameter &#34;newstext       &#34;:&nbsp;<xsl:value-of select="data [@alias = 'newstext']"/>       </p>
                        </li>
                    </xsl:if>       
                </xsl:for-each>
              </ul>
          </xsl:when>

          <xsl:otherwise>
          </xsl:otherwise>
        </xsl:choose>

      </xsl:template>
    </xsl:stylesheet>

    And the result is:

     

    QUESTION:

    why content from "News description" field outputs correctly and content from "News text" field outputs wrong?

    Is it a difference in types of properties or else?

    What to do to output text and images that published in "News text" field in a new page, using xslt?

     

    Thank you!

  • Rick Mather 42 posts 124 karma points
    Dec 07, 2010 @ 13:28
    Rick Mather
    2

    XSLT values are escaped when output - this needs to be disabled for any rich-text content as it includes HTML tags:

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

  • Ol 7 posts 27 karma points
    Dec 07, 2010 @ 14:04
    Ol
    0

    thank you very much!

    can you recomend sources to avoid such mistakes in future? Because I know only this forum.

  • Rick Mather 42 posts 124 karma points
    Dec 07, 2010 @ 15:37
    Rick Mather
    0

    This is more of an XSLT 'gotcha' rather than something specific to Umbraco, though there are some solutions to common XSLT problems in the web-developer section of the wiki - Useful tips and snippets.

     

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies