Copied to clipboard

Flag this post as spam?

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


  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 23, 2009 @ 20:03
    Christopher W. Brandsdal
    0

    Error in tagsLib:getTagsFromNode

    Hi, everyone!

    Having problem listing tags in my blogPost. Everything works fine until I type the tag "Tips & Trics". I get the following action on the line:
    <xsl:for-each select="tagsLib:getTagsFromNode(@id)/tags/tag">

    {"An error occurred while parsing EntityName. Line 2, position 51."}

    It seems that the "&" in the tag is not appreciated by getTagsFromNode.

    Any ideas?

    Best regards,
    Christopher W. B.

  • Chris Koiak 700 posts 2626 karma points
    Aug 23, 2009 @ 20:06
    Chris Koiak
    0

    Try saving the tag as "Tips &amp; Tricks" and it should work.

    However this is a work around and no use if website users are entering tags.

    Where does the tagsLib extension come from? Basically a change needs to be made to HTMLEncode the tags before outputing.

  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 23, 2009 @ 20:12
    Christopher W. Brandsdal
    0

    <Action runat="install" alias="addXsltExtension" assembly="\bin\umbraco.editorControls" type="umbraco.editorControls.tags.library" extensionAlias="tagsLib" />

    It is an action I installed. Ok, so I need to encode.. How will I do that? Here is my code (bold line is where VS is stopping me):

     

    <xsl:template name="showpost">
        <xsl:param name="post"/>
        <div class="post">
            <h2 id="post-{$post/@id}"><a href="{umbraco.library:NiceUrl($post/@id)}"><xsl:value-of select="$post/@nodeName"/></a></h2>
            <small><xsl:value-of select="umbraco.library:LongDate($post/@createDate)"/> by <xsl:value-of select="$post/@creatorName"/> </small>
            <div class="entry">
                <xsl:value-of select="$post/data [@alias = 'bodyText']" disable-output-escaping="yes"/>
            </div>
            <p class="postmetadata">
               
                    Archived as
                    <xsl:for-each select="tagsLib:getTagsFromNode(@id)/tags/tag">
                        <a href="{umbraco.library:NiceUrl($currentPage/@id)}?filterby={.}"><xsl:value-of select="."/></a>
                        <xsl:if test="position() != last()">,</xsl:if>
                    </xsl:for-each>
                    <strong>|</strong>
               
                <xsl:choose>
                    <xsl:when test="count(./node [@nodeTypeAlias = 'BlogPostComment']) = 0">
                        &nbsp;<a href="{umbraco.library:NiceUrl(@id)}#comments">Leave comment</a>
                    </xsl:when>
                    <xsl:when test="count(./node [@nodeTypeAlias = 'BlogPostComment']) = 1">
                        &nbsp;<a href="{umbraco.library:NiceUrl(@id)}#comments">1 comment</a>
                    </xsl:when>
                    <xsl:otherwise>
                        &nbsp;<a href="{umbraco.library:NiceUrl(@id)}#comments"><xsl:value-of select="count(./node [@nodeTypeAlias = 'BlogPostComment'])"/> comments</a>
                    </xsl:otherwise>
                </xsl:choose>
            </p>
        </div>
    </xsl:template>

  • Chris Koiak 700 posts 2626 karma points
    Aug 23, 2009 @ 20:40
    Chris Koiak
    101

    The problem is that the getTagsFromNode doesn't HTML encode.

            public static XPathNodeIterator getTagsFromNode(string nodeId)
    {
    string xmlVal = "<tags>\n";
    string sql = @"SELECT cmsTags.id, cmsTags.tag, cmsTags.[group], count(cmsTagRelationShip.tagid) AS nodeCount FROM cmsTags
    INNER JOIN cmsTagRelationShip ON cmsTagRelationShip.tagid = cmsTags.id
    WHERE cmsTagRelationShip.nodeid = @nodeId
    GROUP BY cmsTags.id, cmsTags.tag, cmsTags.[group]";

    IRecordsReader rr = SqlHelper.ExecuteReader(sql, SqlHelper.CreateParameter("@nodeId", nodeId));

    while (rr.Read())
    {
    xmlVal += "<tag id=\"" + rr.GetInt("id").ToString() + "\" group=\"" + rr.GetString("group") + "\" nodesTagged=\"" + rr.GetInt("nodeCount").ToString() + "\">" + rr.GetString("tag") + "</tag>\n";
    }
    xmlVal += "</tags>";

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xmlVal);

    rr.Close();

    return doc.CreateNavigator().Select(".");
    }

    If I were you I would implement this again changing the above as follows

    .

    xmlVal += "<tag id=\"" + rr.GetInt("id").ToString() + "\" group=\"" + rr.GetString("group") + "\" nodesTagged=\"" + rr.GetInt("nodeCount").ToString() + "\">" + HttpUtility.HtmlEncode( rr.GetString("tag") ) + "</tag>\n";

    I would also implement some caching. This tag library is not very efficient, each extension call results in DB access everytime.

  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 23, 2009 @ 21:03
    Christopher W. Brandsdal
    0

    Ok, thanks!

    I'll just change the tag for now. :-) If I were to change it, would you suggest an override?

  • Chris Koiak 700 posts 2626 karma points
    Aug 23, 2009 @ 21:53
    Chris Koiak
    0

    An override? Sorry, I don't follow.

    If you mean an alternative tagging approach - The company I work for, Conscia, put together a nice tagging datatype... the tag information was stored against the page node. With the accumulated tag count stored in the App context. I'll see if they'll release it this week.

     

  • Christopher W. Brandsdal 72 posts 133 karma points
    Aug 31, 2009 @ 21:40
    Christopher W. Brandsdal
    0

    Ok, thanks fo all the input. :-)

    I just figured I use the built in datatype for now.

  • 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