Copied to clipboard

Flag this post as spam?

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


  • Thanos Panousis 14 posts 34 karma points
    Oct 12, 2011 @ 18:54
    Thanos Panousis
    0

    get a simple Category listing

    Hello nForum people,

    I am an uber umbraco noob. I am trying to create my first xslt/macro ever. The idea is to get a list of forum categories that link to the respective forum.

    This will be a side column of my site that will always be there regardless of where the user is. I am failing miserably.

    Is this possible with xslt? Could you plz give an example?

    Thank you.

  • Tom Hare 49 posts 81 karma points
    Oct 13, 2011 @ 14:04
    Tom Hare
    0

    Hi Thanos,

    The following XSLT should do what you are looking for...

    <!--Test to make sure some categories exist-->
    <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc and @level=1] /Forum//ForumCategory">
    <!--Loop through the categories-->
    <xsl:for-each select="$currentPage/ancestor-or-self::*[@isDoc and @level=1] /Forum//ForumCategory">
        <!--Put your HTML markup here-->
    <p><a href="{umbraco.library:NiceUrl(.)}"><xsl:value-of select="./@nodeName" /></a></p>
    </xsl:for-each>
    <xsl:if>

    Basically, the first bit of the select is getting the root node (the homepage) then it's searching for a node with the document type 'Forum' then any 'ForumCategory' document types that reside under that at any level (this is why there's a double slash - searches all children, not just direct decendents).

    If you only want to get the main forum categories then you'll want to change the select to...

    $currentPage/ancestor-or-self::*[@isDoc and @level=1] /Forum//ForumCategory[forumCategoryIsMainCategory=1]

    Hope that helps.

    Tom

  • Thanos Panousis 14 posts 34 karma points
    Oct 17, 2011 @ 11:55
    Thanos Panousis
    0

    Thank you for your reply Tom.

    I have created the following 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" 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" 
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
     
     
    <xsl:output method="xml" omit-xml-declaration="yes" />
     
    <xsl:param name="currentPage"/>
     
    <xsl:template match="/">
     
    <!--Test to make sure some categories exist-->
    <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc and @level=1] /Forum//ForumCategory">
        <!--Loop through the categories-->
    <ul id="nforumCategoryList">
        <xsl:for-each select="$currentPage/ancestor-or-self::*[@isDoc and @level=1] /Forum//ForumCategory">
            <!--Put your HTML markup here-->
            <li><a href="{umbraco.library:NiceUrl(.)}"><xsl:value-of select="./@nodeName" /></a></li>
        </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
     
    </xsl:stylesheet>

    And I am getting an exception

    System.OverflowException: Value was either too large or too small for an Int32. at System.Convert.ToInt32(Double value) at System.Double.System.IConvertible.ToInt32(IFormatProvider provider) at System.Convert.ChangeType(Object value.

     

    Any ideas? It didn't work to skip testing of the xslt.

Please Sign in or register to post replies

Write your reply to:

Draft