Copied to clipboard

Flag this post as spam?

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


  • Niels 63 posts 119 karma points
    Oct 18, 2012 @ 13:50
    Niels
    0

    Count childnodes with id selected in MultiNodeTreePicker

    Hello Umbracoholics,

    I'm cracking my brain on this one: I want to get a list of items selected(from the childnodes) in the multinodepicker and the problem part is that I can't count this selected items. This list is to filter the childnodes later on.

    So it must look like this:

    City:
    - New York (3)
    - Amsterdam (2)
    - Paris (5)

    Object type:
    - Home
    - Office
    - Garden

    My xslt up to now:

    <xsl:variable name="plaatsnaam" select="umbraco.library:GetXmlNodeById(1104)" />
    <xsl:variable name="objecttype" select="umbraco.library:GetXmlNodeById(1099)" />
    <xsl:variable name="plaatsnaampicker" select="$currentPage/*/plaatsnaam/MultiNodePicker/nodeId" />
    <xsl:variable name="objectpicker" select="$currentPage/*/objecttype/MultiNodePicker/nodeId" />
    <xsl:template match="/">
    <!-- start writing XSLT -->

    <xsl:if test="$currentPage/Object[@isDoc]">
    <xsl:if test="$plaatsnaam/*[@isDoc]">
    <h1><xsl:value-of select="$plaatsnaam/@nodeName" /></h1>
    <ul id="plaatsfilter">
    <xsl:for-each select="$plaatsnaam/*[@isDoc][@id = $plaatsnaampicker]">
    <li>
    <xsl:value-of select="@nodeName" />
    (<xsl:value-of select="count($currentPage/*[@isDoc][@id = $plaatsnaampicker])" />)
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    <xsl:if test="$objecttype/*[@isDoc]">
    <h1><xsl:value-of select="$objecttype/@nodeName" /></h1>
    <ul id="objecttypefilter">
    <xsl:for-each select="$objecttype/*[@isDoc][@id = $objectpicker]">
    <li>
    <xsl:value-of select="@nodeName" />
    (<xsl:value-of select="count($objecttype/*[@isDoc][@id = $objectpicker])" />)</li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:if>

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 18, 2012 @ 23:17
    Chriztian Steinmeier
    1

    Hi Niels,

    If I understand your structure correct, I think this will do the trick - replace the first for-each with this chunk:

    <xsl:for-each select="$plaatsnaam/*[@isDoc][@id = $plaatsnaampicker]">
        <xsl:variable name="plaatsId" select="@id" />
        <li>
            <xsl:value-of select="@nodeName" />
            <xsl:text>(</xsl:text>
            <!-- Count the number of child nodes that point to this place in their pickers -->
            <xsl:value-of select="count($currentPage/*[@isDoc][plaatsnaam//nodeId = $plaatsId])" />
            <xsl:text>)</xsl:text>
        </li>
    </xsl:for-each>
    
    You could probably do something similar in the second part to count the objecttypes too ...

    /Chriztian

  • Niels 63 posts 119 karma points
    Oct 19, 2012 @ 10:08
    Niels
    0

    Yes, thanks Chriztian! That did the trick indeed! For the second part it works out fine too.

Please Sign in or register to post replies

Write your reply to:

Draft