Copied to clipboard

Flag this post as spam?

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


  • Mladen Macanovic 22 posts 45 karma points
    Nov 10, 2010 @ 12:36
    Mladen Macanovic
    0

    recursive function

    What I want to do is to select all child nodes of selected page. The code for the xslt is bellow (it is a code from this link http://forum.umbraco.org/yaf_postst8993_List-entire-structure-from-changeable-source.aspx).

    <?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"/>
        
    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="2"/>
    <xsl:variable name="source" select="/macro/source" /> <!-- a content picker -->
        
    <xsl:template match="/">
      <xsl:call-template name="drawNodes">
            <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById($source)" />
        </xsl:call-template>
    </xsl:template>
        
    <!-- funkcija koja se poziva rekurzivno -->
    <xsl:template name="drawNodes">
        <!-- ulazni parametar za funkciju -->  
        <xsl:param name="parent" />
      
        <ul>       
            <xsl:for-each select="$parent/node">
                <li>
                    <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:value-of select="@nodeName" />
                    </a>
                    
                    <xsl:if test="count(./node) &gt; 0">
                        <!-- this node has children, let's list them also -->
                        <xsl:call-template name="drawNodes">
                            <xsl:with-param name="parent" select="." />
                        </xsl:call-template>
                    </xsl:if>
                </li>
            </xsl:for-each>
        </ul>
    </xsl:template>

    </xsl:stylesheet>

    When it is executed it does nothing except for empy <ul></ul>. The problem is on the line

    <xsl:for-each select="$parent/node">

    it never goes bellow that line. If I try to insert some dummy code eg. <li>123</li> before that line it is shown in the page source. I'm really stucked with this. Anyone have a solution for this please help.

  • John C Scott 473 posts 1183 karma points
    Nov 10, 2010 @ 12:57
    John C Scott
    0

    i have to ask the obvious questions first

    1) have you set a macro parameter for the source ? you can test if this may be the problem by replacing 

    <xsl:variable name="source" select="/macro/source" />

    with <xsl:variable name="source" select="1234" />

    where 1234 is the node id (you get this from the properties tab) of the node you want to list everything beneath

    i've not found another way to test this with the xslt visualiser and I'd be interested in any tips any one else has to test this

    but this needs to be set as a parameter in your macro settings as a content picker called "source" to use it - you will then be prompted for the source you want to use when you add this macro to your template

    2) is the content you are testing on published - also it is often worth republishing nodes if you have a problem like this - you can right click on the root node and choose "republish entire site" and this often solves annoying problems like this one

  • John C Scott 473 posts 1183 karma points
    Nov 10, 2010 @ 12:59
    John C Scott
    0

    also 

    3) are you using version 4 or version 4.5 - due to the schema change the line for the count test may need to be changed

  • John C Scott 473 posts 1183 karma points
    Nov 10, 2010 @ 13:06
    John C Scott
    0

    Using this in 4.5 the code inside the innter template needs to change to:

        <ul>        

            <xsl:for-each select="$parent/* [@isDoc]">

                <li>
                    <href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:value-of select="@nodeName" />
                    </a>
                    

                  <xsl:if test="count(./* [@isDoc]) &gt; 0">

                        <!-- this node has children, let's list them also -->
                        <xsl:call-template name="drawNodes">
                            <xsl:with-param name="parent" select="." />
                        </xsl:call-template>
                    </xsl:if>
                </li>
            </xsl:for-each>
        </ul>

     

  • Mladen Macanovic 22 posts 45 karma points
    Nov 10, 2010 @ 13:15
    Mladen Macanovic
    0

    Yes I have set the macro parameter for the source.

    And yes your solution worked like it should.

    Thank you.

  • John C Scott 473 posts 1183 karma points
    Nov 10, 2010 @ 13:19
    John C Scott
    1

    you are most welcome :)

    by a wonderfully serendipitous karmic moment

    i was searching the forum for a solution to my own problem and this is actually also the solution to that

    i want to give myself a high-five :D

Please Sign in or register to post replies

Write your reply to:

Draft