Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Mar 02, 2010 @ 18:08
    Lee
    0

    Typical Example - How Annoying Is XSLT

    Ok this is bugging the crap out of me... I'm trying to get the latest blog posts from the root Blog which I choose with a content picker - It all saves fine

       <xsl:if test="string(umbraco.library:GetXmlNodeById($latestposts)//node [@nodeTypeAlias = 'BlogPost']) != ''">
    <xsl:for-each select="umbraco.library:GetXmlNodeById($latestposts)//node [@nodeTypeAlias = 'BlogPost']">
    <xsl:sort select="@createDate" order="descending" />
    <xsl:if test="position() &lt; $numberOfPosts">
    <xsl:call-template name="showpost">
    <xsl:with-param name="post" select="."/>
    </xsl:call-template>
    </xsl:if>
    </xsl:for-each>
    </xsl:if>

    <xsl:template name="showpost">
    ... blah blah
    </xsl:template>

    Now if I do this (1092 is the node I have selected in the macro)

    <xsl:copy-of select="umbraco.library:GetXmlNodeById('1092')//node [@nodeTypeAlias = 'BlogPost']"/>

    I get all the XML perfectly, however in the page all I'm getting is

    Error parsing XSLT file: \xslt\BlogPostsLatest.xslt

    What the heck!?? Now explain how this language actually makes sense :S

    So I decided to hard code the nodeId in everything, just to test it and use the same select method I used above in the copy-of (As I know that works)... Yep you guessed it, it works using copy-of / value-of in the XSL visualiser... But If change it to

       <xsl:if test="string(umbraco.library:GetXmlNodeById('1092')//node [@nodeTypeAlias = 'BlogPost']) != ''">
    <xsl:for-each select="umbraco.library:GetXmlNodeById('1092')//node [@nodeTypeAlias = 'BlogPost']">
    ...

    I get this error!?

    asdasd

  • Lee 1130 posts 3088 karma points
    Mar 02, 2010 @ 18:10
  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 02, 2010 @ 18:16
    Peter Dijksterhuis
    0

    Try this:

            <xsl:if test="string($latestposts) != ''">
            <xsl:for-each select="umbraco.library:GetXmlNodeById($latestposts)//node [@nodeTypeAlias = 'BlogPost']">

    HTH,

    Peter

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 02, 2010 @ 18:21
    Peter Dijksterhuis
    0

    Explanation:

    GetXmlNodeById expects an integer. When saving the xslt, umbraco checks against the root-node. This probably doesn't make your $latestposts being filled correctly, thus not being an integer. This results in the error you recieved.

    In your original if-statement, you check against the full path. This doesn't make much sense since the error you got is caused by GetXmlNodeByID and not by the for-each. So, what you actually did was causing the same error twice ;-)

    Hope this clarifies a bit,

    Peter

  • Lee 1130 posts 3088 karma points
    Mar 02, 2010 @ 21:45
    Lee
    0

    Hey Peter

    Thanks for posting, I'm afraid this isn't the cure - I have tried this and get the same error??  Here is the full XSLT

       <xsl:variable name="numberOfPosts" select="4"/>
        <xsl:variable name="latestposts" select="/macro/blognode"/>
    
        <xsl:template match="/">
    
        <xsl:if test="string($latestposts) != ''">
        <xsl:for-each select="umbraco.library:GetXmlNodeById($latestposts)//node [@nodeTypeAlias = 'BlogPost']">
            <xsl:sort select="@createDate" order="descending" />
            <xsl:if test="position() &lt; $numberOfPosts">
              <xsl:call-template name="showpost">
                <xsl:with-param name="post" select="."/>
              </xsl:call-template>
            </xsl:if>
            </xsl:for-each>
        </xsl:if>
    
        </xsl:template>
    
      <xsl:template name="showpost">
        <xsl:param name="post"/>
    
        <div class="hentry post publish author-{$post/@writername} tag-boat tag-lake {umbraco.library:FormatDateTime($post/@updateDate, 'yYYYY mMM')} y2008 m10 d17 h04">
          <h1 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>
          </h1>
    
          <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">
        <p><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml($post/data [@alias = 'bodyText']), 450, '............')" disable-output-escaping="yes" /></p>
          </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>

    Still same error?  As I say if I do a value-of/copy-of I get the results fine?

  • dillorscroft 198 posts 192 karma points
    Mar 02, 2010 @ 22:19
    dillorscroft
    0

    Are you able to post the full XSLT?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 02, 2010 @ 22:42
    Chriztian Steinmeier
    1

    Hi Lee,

    Have you tried a very simple showpost, to determine if the problem is with the node selection or somewhere inside the showpost template?

    E.g., rename your current "showpost" template to "dontshowpost", and use something like this instead:

       <xsl:template name="showpost">
            <xsl:param name="post" />
            <p>I'm the post with id: <xsl:value-of select="$post/@id" />.</p>
        </xsl:template>
    

    /Chriztian

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 02, 2010 @ 22:50
    Kim Andersen
    0

    Hi Lee

    Just a quick idea. Are you sure that you are getting the right node-id from the macro parameter?

    I usually use:

    <xsl:variable name="latestposts" select="macro/blognode"/>

    Instead of this:

    <xsl:variable name="latestposts" select="/macro/blognode"/>

    without the / in the front.

    Maybe this has nothing to do with it, but just to make sure, try to print the $latestposts in a <textarea> and see if the right value is in the variable.

    This is a wild shot, so like dillorscroft says, could you post your full XSLT-file? I think that this could help. Otherwise, try using the umbdebugshowtrace=true parameter in the URL and see if you are getting any errors.

    /Kim A

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Mar 02, 2010 @ 22:52
    Peter Dijksterhuis
    1

    Lee,

    There are a few NiceUrl(@id) in your template and a tagsLib:getTagsFromNode(@id). I think they should be replaced with NiceUrl($post/@id).

    Could you try that and report back?

    Peter

    PS: if you try Chriztian's example, if that works, you know the fault is in the template. And I might be right then.

  • Lee 1130 posts 3088 karma points
    Mar 03, 2010 @ 07:38
    Lee
    0

    Ok thanks to Peter it was in the template :)  

    It was in the for each section of the tags, here

    <a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::node [@nodeTypeAlias = 'Blog']/@id)}?filterby={.}" rel="tag">

    I changed it to

    <a href="{umbraco.library:NiceUrl(umbraco.library:GetXmlNodeById($latestposts)/@id)}?filterby={.}" rel="tag">

    And we are in business :)

Please Sign in or register to post replies

Write your reply to:

Draft