Copied to clipboard

Flag this post as spam?

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


  • Jonathan Lathigee 56 posts 99 karma points
    Jun 02, 2010 @ 20:20
    Jonathan Lathigee
    0

    Macro in Content in XSLT

    I have some content (using Blog4Umbraco) that is editable with the richText editor, and into which users can insert a macro (the Indsæt video macro). If I render out the content via template, the macro is interpretted correctly and the video shows up in the blog posting.

    I also have an XSLT / Macro (called blogListPostsWithOneMain) with the following:

      <xsl:template name="showpostfirst">
        <xsl:param name="post" />
        <div class="entry post publish author-{$post/@writername} tag-boat tag-lake {umbraco.library:FormatDateTime($post/@updateDate, 'yYYYY mMM')} y2008 m10 d17 h04">
          <h2 class="entry-title" id="post-{$post/@id}">
            <a href="{umbraco.library:NiceUrl($post/@id)}"
            title="Permalink to {$post/@nodeName}">
              <xsl:value-of select="$post/@nodeName" />
            </a>
          </h2>
          <div class="entry-date">
            <abbr class="published"
            title="umbraco.library:ShortDate($post/@updateDate">
              <xsl:value-of select="umbraco.library:LongDate($post/@updateDate)" />
            </abbr>
          </div>
          <div class="entry-content">
            <xsl:value-of select="$post/data [@alias = 'summaryMedium']"
            disable-output-escaping="yes" />
          </div>
    <-- SNIP -->
        </div>
      </xsl:template>

    When the template renders, pulling in this macro, which in turn pulls in the content 'summaryMedium' (that itself contains a macro), the resulting output is invalid. It contains something along the lines of:

    <?UMBRACO_MACRO maxwidth="300"
    sourceurl="http://vimeo.com/11480419" macroAlias="OEmbed"
    maxheight="250" />

    (ie it looks like it's just pulling the macro reference from the content, and not rendering it)

    Is there a way to get this internal macro to render?

    thanks in advance

    Jonathan

  • dandrayne 1138 posts 2262 karma points
    Jun 02, 2010 @ 20:36
    dandrayne
    0

    Hi Jonathan

    Try this

     <xsl:value-of select="umbraco.library:RenderMacroContent($post/data [@alias = 'summaryMedium'])"
           
    disable-output-escaping="yes" />

    Dan

  • Jonathan Lathigee 56 posts 99 karma points
    Jun 02, 2010 @ 21:05
    Jonathan Lathigee
    0

    Hi Dan

    Thanks for that. My updated XSLT saves fine in umbraco (no validation errors), but when outputting on the web page returns:

    Error parsing XSLT file: \xslt\BlogListPostsWithOneMain.xslt

    Also, I looked briefly at RenderMacroContent at http://en.wikibooks.org/wiki/Umbraco/Reference/umbraco.library/RenderMacroContent but my understanding was that this was for explicitly rendering a macro (ie you need to provide a macro to render) as opposed to rendering an XML node that may or may not contain a macro. Maybe I'm wrong? And, just because, I'm including my full XSLT below. look for "<!-- PROBLEM AREA -->"

    Thanks

    Jonathan

    <?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:tagsLib="urn:tagsLib"
    xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
    xmlns:BlogLibrary="urn:BlogLibrary"
    exclude-result-prefixes="msxml umbraco.library tagsLib Exslt.ExsltStrings BlogLibrary">
      <xsl:output method="html" omit-xml-declaration="yes" />
      <xsl:param name="currentPage" />
      <xsl:variable name="numberOfPosts" select="10" />
      <xsl:variable name="pageNumber">
        <xsl:choose>
          <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">
          1</xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="umbraco.library:RequestQueryString('page')" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="filter">
        <xsl:choose>
          <xsl:when test="string-length(umbraco.library:Request('filterby')) &gt; 0">
            <xsl:value-of select="umbraco.library:Request('filterby')" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="''" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="numberOfRecords">
        <xsl:choose>
          <xsl:when test="$filter = ''">
            <xsl:value-of select="count($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost'])" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="count($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost' and contains(Exslt.ExsltStrings:lowercase(./data [@alias='tags']), Exslt.ExsltStrings:lowercase($filter))])" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:template match="/">
        <xsl:if test="$filter != ''">
          <h2 class="page-title">Archive for tag:
          <span>
            <xsl:value-of select="$filter" />
          </span></h2>
        </xsl:if>
        <xsl:if test="$currentPage/@nodeTypeAlias = 'DateFolder'">
          <h2 class="page-title">Monthly Archives:
          <xsl:value-of select="umbraco.library:FormatDateTime(concat($currentPage/../@nodeName,'-',$currentPage/@nodeName,'-11T10:24:46'),'MMMM yyyy')" /></h2>
        </xsl:if>
        <xsl:if test="$numberOfRecords &gt; $numberOfPosts">
          <div id="nav-above" class="navigation">
            <div class="nav-previous">
              <xsl:if test="(($pageNumber ) * $numberOfPosts) &lt; ($numberOfRecords)">
                <span class="meta-nav">&#171;</span>
                <a href="?page={$pageNumber +1}">Older posts</a>
              </xsl:if>
            </div>
            <div class="nav-next">
              <xsl:if test="$pageNumber &gt; 1">
                <a href="?page={$pageNumber -1}">Newer posts</a>
                <span class="meta-nav">&#187;</span>
              </xsl:if>
            </div>
          </div>
        </xsl:if>
        <xsl:if test="$filter = ''">
          <xsl:for-each select="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost']">
            <xsl:sort select="@createDate" order="descending" />
            <xsl:if test="position() &gt; $numberOfPosts * (number($pageNumber)-1) and position() &lt;= number($numberOfPosts * (number($pageNumber)-1) + $numberOfPosts )">
              <xsl:if test="position() = 1">
                <xsl:call-template name="showpostfirst">
                  <xsl:with-param name="post" select="." />
                </xsl:call-template>
              </xsl:if>
              <xsl:if test="position() &gt; 1">
                <xsl:call-template name="showpost">
                  <xsl:with-param name="post" select="." />
                </xsl:call-template>
              </xsl:if>
            </xsl:if>
          </xsl:for-each>
        </xsl:if>
        <xsl:if test="$filter != ''">
          <xsl:for-each select="$currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']//node [@nodeTypeAlias = 'BlogPost' and contains(Exslt.ExsltStrings:lowercase(./data [@alias='tags']), Exslt.ExsltStrings:lowercase($filter))]">
            <xsl:sort select="@createDate" order="descending" />
            <xsl:if test="position() &gt; $numberOfPosts * (number($pageNumber)-1) and position() &lt;= number($numberOfPosts * (number($pageNumber)-1) + $numberOfPosts )">
              <xsl:if test="position() = 1">
                <xsl:call-template name="showpostfirst">
                  <xsl:with-param name="post" select="." />
                </xsl:call-template>
              </xsl:if>
              <xsl:if test="position() &gt; 1">
                <xsl:call-template name="showpost">
                  <xsl:with-param name="post" select="." />
                </xsl:call-template>
              </xsl:if>
            </xsl:if>
          </xsl:for-each>
        </xsl:if>
        <div id="nav-below" class="navigation">
          <div class="nav-previous">
            <xsl:if test="(($pageNumber ) * $numberOfPosts) &lt; ($numberOfRecords)">
              <span class="meta-nav">&#171;</span>
              <a href="?page={$pageNumber +1}">Older posts</a>
            </xsl:if>
          </div>
          <div class="nav-next">
            <xsl:if test="$pageNumber &gt; 1">
              <a href="?page={$pageNumber -1}">Newer posts</a>
              <span class="meta-nav">&#187;</span>
            </xsl:if>
          </div>
        </div>
      </xsl:template>
      <xsl:template name="showpostfirst">
        <xsl:param name="post" />
        <div class="entry post publish author-{$post/@writername} tag-boat tag-lake {umbraco.library:FormatDateTime($post/@updateDate, 'yYYYY mMM')} y2008 m10 d17 h04">
          <h2 class="entry-title" id="post-{$post/@id}">
            <a href="{umbraco.library:NiceUrl($post/@id)}"
            title="Permalink to {$post/@nodeName}">
              <xsl:value-of select="$post/@nodeName" />
            </a>
          </h2>
          <div class="entry-date">
            <abbr class="published"
            title="umbraco.library:ShortDate($post/@updateDate">
              <xsl:value-of select="umbraco.library:LongDate($post/@updateDate)" />
            </abbr>
          </div>
          <div class="entry-content">
    <!-- PROBLEM AREA -->
            <xsl:value-of select="$post/data [@alias = 'summaryMedium']" disable-output-escaping="yes" />
            <xsl:value-of select="umbraco.library:RenderMacroContent($post/data [@alias = 'summaryMedium'])" disable-output-escaping="yes" />
          </div>
          <div class="entry-meta">
            <span class="author vcard">By:
            <span class="fn n">
              <xsl:value-of select="$post/@creatorName" />
            </span></span>
            <span class="meta-sep">|</span>
            <span class="tag-links">
              <xsl:variable name="tags"
              select="tagsLib:getTagsFromNode(@id)" />
              <xsl:choose>
                <xsl:when test="count($tags/tags/tag) = 0">Not
                tagged</xsl:when>
                <xsl:otherwise>Tagged:
                <xsl:for-each select="$tags/tags/tag">
                  <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']/@id)}?filterby={.}"
                  rel="tag">
                    <xsl:value-of select="." />
                  </a>
                  <xsl:if test="position() != last()">,</xsl:if>
                </xsl:for-each></xsl:otherwise>
              </xsl:choose>
            </span>
            <span class="meta-sep">|</span>
            <xsl:variable name="numberofcomments"
            select="count(BlogLibrary:GetCommentsForPost($post/@id)//comment)" />
            <span class="comments-link">
              <xsl:choose>
                <xsl:when test="$numberofcomments = 0">
                  <xsl:choose>
                    <xsl:when test="string($post/data [@alias = 'closeComments']) = '1'">
                    Comments closed</xsl:when>
                    <xsl:otherwise>
                      <a href="{umbraco.library:NiceUrl(@id)}#comments">
                      Leave comment</a>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$numberofcomments = 1">
                  <a href="{umbraco.library:NiceUrl(@id)}#comments">1
                  comment</a>
                </xsl:when>
                <xsl:otherwise>
                  <a href="{umbraco.library:NiceUrl(@id)}#comments">
                  <xsl:value-of select="$numberofcomments" />comments</a>
                </xsl:otherwise>
              </xsl:choose>
            </span>
          </div>
        </div>
      </xsl:template>
      <xsl:template name="showpost">
        <xsl:param name="post" />
        <div class="entry post publish author-{$post/@writername} tag-boat tag-lake {umbraco.library:FormatDateTime($post/@updateDate, 'yYYYY mMM')} y2008 m10 d17 h04">
          <h2 class="entry-title" id="post-{$post/@id}">
            <a href="{umbraco.library:NiceUrl($post/@id)}"
            title="Permalink to {$post/@nodeName}">
              <xsl:value-of select="$post/@nodeName" />
            </a>
          </h2>
          <div class="entry-date">
            <abbr class="published"
            title="umbraco.library:ShortDate($post/@updateDate">
              <xsl:value-of select="umbraco.library:LongDate($post/@updateDate)" />
            </abbr>
          </div>
          <div class="entry-content">
            <h1>
              <xsl:value-of select="position()" />
            </h1>
            <xsl:value-of select="$post/data [@alias = 'summarySmall']"
            disable-output-escaping="yes" />
          </div>
          <div class="entry-meta">
            <span class="author vcard">By:
            <span class="fn n">
              <xsl:value-of select="$post/@creatorName" />
            </span></span>
            <span class="meta-sep">|</span>
            <span class="tag-links">
              <xsl:variable name="tags"
              select="tagsLib:getTagsFromNode(@id)" />
              <xsl:choose>
                <xsl:when test="count($tags/tags/tag) = 0">Not
                tagged</xsl:when>
                <xsl:otherwise>Tagged:
                <xsl:for-each select="$tags/tags/tag">
                  <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']/@id)}?filterby={.}"
                  rel="tag">
                    <xsl:value-of select="." />
                  </a>
                  <xsl:if test="position() != last()">,</xsl:if>
                </xsl:for-each></xsl:otherwise>
              </xsl:choose>
            </span>
            <span class="meta-sep">|</span>
            <xsl:variable name="numberofcomments"
            select="count(BlogLibrary:GetCommentsForPost($post/@id)//comment)" />
            <span class="comments-link">
              <xsl:choose>
                <xsl:when test="$numberofcomments = 0">
                  <xsl:choose>
                    <xsl:when test="string($post/data [@alias = 'closeComments']) = '1'">
                    Comments closed</xsl:when>
                    <xsl:otherwise>
                      <a href="{umbraco.library:NiceUrl(@id)}#comments">
                      Leave comment</a>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$numberofcomments = 1">
                  <a href="{umbraco.library:NiceUrl(@id)}#comments">1
                  comment</a>
                </xsl:when>
                <xsl:otherwise>
                  <a href="{umbraco.library:NiceUrl(@id)}#comments">
                  <xsl:value-of select="$numberofcomments" />comments</a>
                </xsl:otherwise>
              </xsl:choose>
            </span>
          </div>
        </div>
      </xsl:template>
    </xsl:stylesheet>

     

  • dandrayne 1138 posts 2262 karma points
    Jun 02, 2010 @ 23:31
    dandrayne
    0

    Apologies! I should have known better, as I ran up against this very problem myself when using my own insert video package. As far as I can remember, I had to find a way to get the rich text editor content back in the templates and out of xslt...

     

Please Sign in or register to post replies

Write your reply to:

Draft