Copied to clipboard

Flag this post as spam?

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


  • hssdev 5 posts 25 karma points
    Jul 10, 2010 @ 11:53
    hssdev
    0

    xslt list sub pages problem

    Hi guys, am a seasoned .net developer creating my first umbraco 4.0.4.1 site and have a problem, the below macro which has been modified for paging and order by functionality renders fine when i use it to show my list of members and my list of member servces but does not render fine when it comes to my news stories, when it renders fine i get :-

    <UL xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes">
    <LI><A href="/new2.aspx">new2</A>&nbsp;
    <LI><A href="/new3.aspx">new3Fitness</A>&nbsp;
    <LI><A href="/new4.aspx">new4</A>&nbsp;</LI></UL>

    which is great, but i have a news node with news item sub-nodes.  The same xslt renders only :-

     <UL xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"></UL>

    Would greatly appreciate some help my xslt file is :-

    <?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.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
        exclude-result-prefixes="msxml umbraco.library">
        <xsl:output method="xml" omit-xml-declaration="yes"/>
        <xsl:param name="currentPage"/>
        <!-- These global variables passed in from Macro -->
        <!-- The attribute in the node to sort by (createDate, updateDate, nodeName etc.) OR a 'friendly title' from page property -->
        <xsl:variable name="sortBy" select="/macro/sortBy"/>
        <!-- Sort direction - either 'ascending' or 'descending' -->
        <xsl:variable name="sortDirection" select="/macro/sortDirection"/>
        <!-- Optional document alias to only return documents of that type -->
        <xsl:variable name="nodeTypeAlias" select="/macro/nodeTypeAlias"/>
        <!-- Date format string - standard .NET formatting eg. 'd' or 'D' -->
        <xsl:variable name="dateFormatString" select="/macro/dateFormatString"/>
        <!-- Set to '1' to show date -->
        <xsl:variable name="showDate" select="/macro/showDate"/>
        <!-- Set to '1' to show pagination numbers -->
        <xsl:variable name="showPageNumbers" select="1"/>
        <!-- Set to '1' to output debug paramaters -->
        <xsl:variable name="showDebug" select="/macro/showDebug"/>
        <!-- Checks if 'sortBy' variable has a 'friendly title' and assigns it to $orderBy variable (otherwise uses value of $sortBy) -->
        <xsl:variable name="orderBy">
            <xsl:choose>
                <xsl:when test="$sortBy = 'Created Date'">createDate</xsl:when>
                <xsl:when test="$sortBy = 'Edited Date'">updateDate</xsl:when>
                <xsl:when test="$sortBy = 'Page Title'">nodeName</xsl:when>
                <xsl:when test="$sortBy = 'Menu Order'"></xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$sortBy"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <!-- This holds the value of the sortBy column and is used to evaluate if it's a date -->
        <xsl:variable name="dateString" select="$orderBy"/>
        <xsl:variable name="pageQS" select="umbraco.library:RequestQueryString('page')" />
        <!-- Variables used for pagination -->
        <xsl:variable name="pageNumber">
            <xsl:choose>
                <xsl:when test="$pageQS &lt;= 0 or string($pageQS) = '' or string($pageQS) = 'NaN'">1</xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <!-- Number of records per page (from Macro but defaults to 10) -->
        <xsl:variable name="recordsPerPage">
            <xsl:choose>
                <xsl:when test="/macro/recordsPerPage">
                    <xsl:value-of select="/macro/recordsPerPage"/>
                </xsl:when>
                <xsl:otherwise>35</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <!-- End Global Variable Declaration -->
        <!-- This template performs matches and sort -->
        <xsl:template match="/">
            <!-- Count child nodes to get number of records -->
            <xsl:variable name="numberOfRecords" select="count($currentPage/node)"/>
            <!-- Debug info (show if macro passes showDebug = '1') -->
            <xsl:if test="$showDebug ='1'">
                <div style="background-color:yellow;border:1px solid red; color:#006;padding:5px">
                    <h2>DEBUG</h2>
                    numberOfRecords = <xsl:value-of select="$numberOfRecords"/><br />
                    recordsPerPage = <xsl:value-of select="$recordsPerPage"/><br />
                    current page = <xsl:value-of select="$pageNumber"/><br />
                    sortBy = <xsl:value-of select="$sortBy"/><br />
                    orderBy = <xsl:value-of select="$orderBy"/><br />
                    sortDirection = <xsl:value-of select="$sortDirection"/><br />
                </div>
            </xsl:if>
            <!-- Start Outer HTML list wrapper -->
            <ul>
                <!-- Apply sorting (annoyingly order has to be a constant and can't be a variable) and nodeTypeAlias filtering -->
                <xsl:choose>
                    <!-- Ascending -->
                    <xsl:when test="$sortDirection = 'ascending'">
                        <xsl:apply-templates select="$currentPage/node [(@nodeTypeAlias = $nodeTypeAlias or $nodeTypeAlias = not(string(.))) and string(data [@alias='umbracoNaviHide']) != '1']">
                            <xsl:sort select="@*[name()=$orderBy]" order="ascending" data-type="text" />
                        </xsl:apply-templates>
                    </xsl:when>
                    <!-- Descending -->
                    <xsl:otherwise>
                        <xsl:apply-templates select="$currentPage/node [(@nodeTypeAlias = $nodeTypeAlias or $nodeTypeAlias = not(string(.))) and string(data [@alias='umbracoNaviHide']) != '1']">
                            <xsl:sort select="@*[name()=$orderBy]" order="descending" data-type="text" />
                        </xsl:apply-templates>
                    </xsl:otherwise>
                </xsl:choose>
            </ul>
            <!-- End Outer HTML -->
            <!-- Start Paging Links -->
            <xsl:if test="$recordsPerPage &lt; $numberOfRecords">
                <hr />
                <!-- Previous Link -->
                <xsl:if test="$pageNumber &gt; 1">
                    <a href="?page={$pageNumber -1}"> &lt; Previous </a>
                </xsl:if>
                <!-- Output page number links, if set -->
                <xsl:if test="$showPageNumbers ='1'">
                    <xsl:call-template name="for.loop">
                        <xsl:with-param name="i">1</xsl:with-param>
                        <xsl:with-param name="page" select="$pageNumber +1"></xsl:with-param>
                        <xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>
                    </xsl:call-template>
                </xsl:if>
                <!-- Next Link -->
                <xsl:if test="(($pageNumber ) * $recordsPerPage) &lt; ($numberOfRecords)">
                    <a href="?page={$pageNumber +1}"> Next &gt; </a>
                </xsl:if>
            </xsl:if>
            <!-- End Paging Links -->
        </xsl:template>
        <!-- This template matches each node in the list and displays each item's HTML -->
        <xsl:template match="node">
            <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber -1) and position() &lt;= number($recordsPerPage * number($pageNumber -1) + $recordsPerPage )">
                <!-- Start individual record -->
                <li>
                    <!-- End Paging Links -->
                    <xsl:if test="$showDate = '1'">
                        <!-- Hack to check if the value of $dateString is a date -->
                        <xsl:variable name="testDate" select="Exslt.ExsltDatesAndTimes:year(@*[name()=$dateString])"/>
                        <xsl:choose>
                            <xsl:when test="string($testDate) != 'NaN'">
                                <h4>
                                    Date: <xsl:value-of select="umbraco.library:FormatDateTime(@*[name()=$dateString],string($dateFormatString))"/>
                                </h4>
                            </xsl:when>
                            <xsl:otherwise>
                                <h4>
                                    Default Date: <xsl:value-of select="umbraco.library:FormatDateTime(@createDate,string($dateFormatString))"/>
                                </h4>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:if>
                    <!-- Title Link -->
      <xsl:if test="data [@alias = 'Premium'] != 1">
       <xsl:value-of select="@nodeName"/>
       &#160;<xsl:value-of select="data [@alias = 'searchResultDescription']"/>
      </xsl:if>
      <xsl:if test="data [@alias = 'Premium'] = 1">
       <a href="{umbraco.library:NiceUrl(@id)}">
       <xsl:value-of select="@nodeName"/>
       </a>&#160;<xsl:value-of select="data [@alias = 'searchResultDescription']"/>
      </xsl:if>
                </li>
                <!-- End individual record -->
            </xsl:if>
        </xsl:template>
        <!-- End Node match template -->

        <!-- Generate Pagination Numbers Loop -->
        <xsl:template name="for.loop">
            <xsl:param name="i"/>
            <xsl:param name="count"/>
            <xsl:param name="page"/>
           
            <xsl:if test="$i &lt;= $count">
                <xsl:if test="$page != ($i + 1)">
                    <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i}" style="padding-left:1em" >
                        <xsl:value-of select="$i" />
                    </a>
                </xsl:if>
                <xsl:if test="$page = ($i + 1) ">
                    <span style="padding-left:1em">
                        <xsl:value-of select="$i" />
                    </span>
                </xsl:if>
            </xsl:if>
            <xsl:if test="$i &lt;= $count">
                <xsl:call-template name="for.loop">
                    <xsl:with-param name="i">
                        <xsl:value-of select="$i + 1" />
                    </xsl:with-param>
                    <xsl:with-param name="count">
                        <xsl:value-of select="$count"/>
                    </xsl:with-param>
                    <xsl:with-param name="page">
                        <xsl:value-of select="$page"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:if>
        </xsl:template>
        <!-- End Generate Pagination Numbers Loop -->

    </xsl:stylesheet>

    Thanks in advance :)

  • Pat O'Callaghan 34 posts 56 karma points
    Jul 11, 2010 @ 10:46
    Pat O'Callaghan
    0

    Can't see myself what the problem is but what I'd do is to try and narrow it down and see where the logic is breaking down. Throw in a few debug statements.

    Is it getting inside the Node template or is the apply-templates failing? is the IF statement within the Node template failing?

    just some more info though, is $currentpage the News page and the news items, the sub items, like this:

    News

    -News Item

    -News Item

    Does this differ from how the member and member services layout or is it the same? Do you need $currentPage/node::descendant-or-self in the apply-templates?

    Sorry couldn't be of more help.

Please Sign in or register to post replies

Write your reply to:

Draft