Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Feb 04, 2010 @ 12:12
    Dan
    1

    Get tags from all subnodes of a particular node

    Hi,

    I'm trying to get a list of all tags in all subnodes of a particular node.  The code I have almost works, but it's duplicating the tags for each of the subnodes.  How can I modify this just to pick out the tags once?

    <xsl:for-each select="umbraco.library:GetXmlNodeById(2140)//node">
    <xsl:for-each select="tagsLib:getTagsFromNode(current()/@id)/tags/tag">
    <li>
    <xsl:value-of select="."/>
    </li>
    </xsl:for-each>
    </xsl:for-each>

    Thanks all...

  • dandrayne 1138 posts 2262 karma points
    Feb 04, 2010 @ 12:17
  • Dan 1288 posts 3921 karma points c-trib
    Feb 04, 2010 @ 12:34
    Dan
    0

    Thanks Dan - I'd seen that post, but am not too keen on swapping the tag data types for plain text, as much of the data has already been populated.  I tried the solution from Gerty but couldn't get that to work.  The code I have above does work, except that it returns the tags for each of the nodes, so they get repeated.  I'll try to explain...

    My structure is like this:

    Home
    - Gallery
    -- Gallery item 1 (contains a tag 'field')
    -- Gallery item 2 (contains a tag 'city')
    -- Gallery item 3 (contains a tag 'beach')

    So what I want to get is a list of all tags under the gallery node (node id 2140).  The code above returns them all for each gallery item, so it's returning:

    <li>field</li>
    <li>field</li>
    <li>field</li>
    <li>city</li>
    <li>city</li>
    <li>city</li>
    <li>beach</li>
    <li>beach</li>
    <li>beach</li>

    What I need to return though is just:

    <li>field</li>
    <li>city</li>
    <li>beach</li>

    I think it's something to do with the fact that I'm looping through the nodes, and it must be returning the full set of tags for each node, but I'm not able to get it to just get the tags for one of the nodes.  I've tried this, but I think my syntax is wrong as it returns nothing:

    <xsl:for-each select="umbraco.library:GetXmlNodeById(2140)//node/tags/tag">
            <li>
                   
    <xsl:value-of select="."/>
           
    </li>
    </xsl:for-each>

    Any ideas, or do I really have to abandon tags completely?

  • Dan 1288 posts 3921 karma points c-trib
    Feb 04, 2010 @ 12:43
    Dan
    0

    Ah-ha!  Got it actually.  I found a great blog post on tags.

    My working solution assumes that I put all tags under the main node in a certain group, which is doable I think:

    <xsl:for-each select="tagsLib:getAllTagsInGroup('myTagGroup')/tags/tag">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}?filterby={current()}"><xsl:value-of select="current()"/></a>
    </li>
    </xsl:for-each>
Please Sign in or register to post replies

Write your reply to:

Draft