Copied to clipboard

Flag this post as spam?

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


  • Gary 40 posts 129 karma points
    Aug 22, 2013 @ 11:36
    Gary
    0

    Display certain nodes

    Hello,

    I would like to display certain child nodes with a specific template only. My structure is like this

    Parent node

    Child node (template 1)

    Child node (template 1)

    Child node (template 1)

    Child node (template 2)

    Child node (template 2)

    Child node (template 2)

    I only want the child nodes with (template 2) to be displayed on the page.

    Can anyone give me any guidance?

    My xslt is as follows

    <table class="tableId">
        <tr><th>Title</th></tr>
        <xsl:variable name="orgNode" select="umbraco.library:GetXmlNodeById(parentID)/ancestor-or-self::Template2"/>
        <xsl:for-each select="$orgNode">
            <xsl:sort select="@nodeName" data-type="text" order="ascending"/>
            <tr>
                <td><a href="{umbraco.library:NiceUrl(@id)}" ><xsl:value-of select="@nodeName"/></a></td>
            </tr>
    </xsl:for-each>
    </table>
    

    Thanks for looking

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 22, 2013 @ 11:53
    Chriztian Steinmeier
    100

    Hi Gary,

    You should be able to use the @template attribute for that - try this:

    Get the ID of your "template 2" from the Settings section - hovering it's node in the Settings tree should give you its ID in the browser's statusbar - something like this:

    run script openTemplate(1062); (or similar).

    Then you use that in your XSLT like this:

    <xsl:variable name="orgNode" select="umbraco.library:GetXmlNodeById(parentID)"/>
    <xsl:variable name="templateID" select="1062" /><!-- Change the ID in this line -->
    <table class="tableId">
        <tr><th>Title</th></tr>
        <xsl:for-each select="$orgNode/*[@isDoc][@template = $templateID]">
            <xsl:sort select="@nodeName" data-type="text" order="ascending"/>
            <tr>
                <td>
                    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
                </td>
            </tr>
        </xsl:for-each>
    </table>
    

    /Chriztian

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 22, 2013 @ 11:56
    Chriztian Steinmeier
    0

    ... Hmm, were you actually referring to the Document Type as "template"?

    Let me know, and it should be easy to change, if so...

    /Chriztian

  • Gary 40 posts 129 karma points
    Aug 22, 2013 @ 14:50
    Gary
    0

    Hi Chriztian,

    Your solution worked perfectly!! Thank you so much for taking the time to help me with this. It's very much appreciated!!!

    Fantastic!

    Gary

  • Gary 40 posts 129 karma points
    Aug 29, 2013 @ 12:08
    Gary
    0

    Hi Chriztian,

    thanks for your help so far.

    I am using this code...

    <xsl:variable name="orgNode" select="umbraco.library:GetXmlNodeById(4257)"/>
    <xsl:variable name="templateID" select="4841" />
    
        <strong>Find organisation alphabetically</strong><br /><br />
    
            <xsl:for-each select="$orgNode/*[@isDoc][@template = $templateID]">
            <xsl:sort select="@nodeName" data-type="text" order="ascending"/>   
            <a href="{umbraco.library:NiceUrl(@id)}" style="float:left; margin: 0 20px 10px 0;"><xsl:value-of select="@nodeName"/></a>
        </xsl:for-each>
    

    How can i make it that the link would only be active if there is child nodes? If there are no child nodes, still display but make it a dead link so to speak.

    Thanks

    Gary

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 29, 2013 @ 12:16
    Chriztian Steinmeier
    1

    Hi Gary,

    You can actually just add an <xsl:attribute> override inside if necessary:

    <xsl:variable name="orgNode" select="umbraco.library:GetXmlNodeById(4257)"/>
    <xsl:variable name="templateID" select="4841" />
    
    <strong>Find organisation alphabetically</strong><br /><br />
    
    <xsl:for-each select="$orgNode/*[@isDoc][@template = $templateID]">
        <xsl:sort select="@nodeName" data-type="text" order="ascending"/>   
        <a href="{umbraco.library:NiceUrl(@id)}" style="float:left; margin: 0 20px 10px 0;">
            <!-- Clear href if no childnodes -->
            <xsl:if test="not(*[@isDoc])">
                <xsl:attribute name="href">#</xsl:attribute>
            </xsl:if>
            <xsl:value-of select="@nodeName" />
        </a>
    </xsl:for-each>
    

    - Of course you can use the [@template = $templateID] predicate in there too, if necessary.

    /Chriztian

  • Gary 40 posts 129 karma points
    Aug 29, 2013 @ 12:28
    Gary
    0

    Thanks for the quick reply Chriztian.

    This is great thanks.

    But just to be a pain.... Do you know how i could make it so that the node still appears but has no href?

    Thanks for all your help,

    Gary

  • Gary 40 posts 129 karma points
    Aug 29, 2013 @ 13:17
    Gary
    0
  • Gary 40 posts 129 karma points
    Sep 03, 2013 @ 16:59
    Gary
    0

    Hi Chriztian.

    your help above is greatly appreciated and works great.

    I was wondering if you could guide me a little further on this?

    I am using this xslt.

    <xsl:variable name="orgNode" select="umbraco.library:GetXmlNodeById(4257)"/>
    <xsl:variable name="templateID" select="4841" />
    
    <strong>Find organisation alphabetically</strong><br /><br />
    
    <xsl:for-each select="$orgNode/*[@isDoc][@template = $templateID]">
    
    
        <xsl:sort select="@nodeName" data-type="text" order="ascending"/>   
        <a href="{umbraco.library:NiceUrl(@id)}" style="float:left; margin: 0 20px 10px 0;">    
            <xsl:if test="not(*[@isDoc])">
                <xsl:attribute name="style">color:#ccc;float:left; margin: 0 20px 10px 0;cursor:text;</xsl:attribute><xsl:attribute name="href">#</xsl:attribute>
            </xsl:if>
            <xsl:value-of select="@nodeName"/>
        </a>
    </xsl:for-each>
    

    I have also created a Data type that is a check box list.

    Option 1 (Value 205)

    Option 2 (value 206) and so on.

    Do you know how i can modify the xslt to only show the nodes with a specific value (say 205)?

    Thanks

    Gary

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Sep 04, 2013 @ 09:04
    Chriztian Steinmeier
    0

    Hi Gary,

    Sure - you'll need to know the alias of the property using that Data Type, and then you will need to know how the values are stored. If I remember correctly, you're getting a CSV list of the checked boxes, so you'll need to use the Split() extension to get a set of value elements that you can match against, like this:

    <xsl:for-each select="$orgNode/*[@isDoc][@template = $templateID][umbraco.library:Split(PROPERTYALIAS, ',')/value = 205]">
    

    /Chriztian

  • Gary 40 posts 129 karma points
    Sep 04, 2013 @ 11:17
    Gary
    0

    Hi Chriztian,

    thank you again for your reply. the alias is 'portalOrgType' and I am using your above method like so.

    <xsl:variable name="orgNode" select="umbraco.library:GetXmlNodeById(4257)"/>
    <xsl:variable name="templateID" select="4841" />
    
    <strong>Find organisation alphabetically</strong><br /><br />
    
    <xsl:for-each select="$orgNode/*[@isDoc][@template = $templateID][umbraco.library:Split(portalOrgType, ',')/value = 205]">
        <xsl:sort select="@nodeName" data-type="text" order="ascending"/>   
        <a href="{umbraco.library:NiceUrl(@id)}" style="float:left; margin: 0 20px 10px 0;">    
            <xsl:if test="not(*[@isDoc])">
                <xsl:attribute name="style">color:#ccc;float:left; margin: 0 20px 10px 0;cursor:text;</xsl:attribute><xsl:attribute name="href">#</xsl:attribute>
            </xsl:if>
            <xsl:value-of select="@nodeName"/>
        </a>
    </xsl:for-each>
    

    although for me this isn't returning any results - no error, just no results :(

Please Sign in or register to post replies

Write your reply to:

Draft