Search

Hello all, I’m trying to use this post as an example of how to get a list without any duplicates using XSLT. I am getting tags, but I don’t want to use a custom datasource because I want to find all of the tags used by a specific bunch of entries, not all of them.

Right now it is still listing all of the tags without taking out the duplicates, am I missing something?

Here’s what I’m trying in my XSLT:

<xsl:for-each select="all-tags//item[not(. = following::item)]">
<li><a href="#"><xsl:value-of select="."/></a>, </li>
</xsl:for-each>

And here’s a shortened version of my XML:

<all-tags>
<section id="7" handle="issues">Issues</section>
        <entry id="44" comments="0">
            <tags>
                <item handle="w00t">w00t</item>
            </tags>
        </entry>
        <entry id="42" comments="0">
            <tags>
                <item handle="optical">Optical</item>
                <item handle="test">Test</item>
                <item handle="w00t">w00t</item>
            </tags>
        </entry>
        <entry id="16" comments="4">
            <tags>
                <item handle="w00t">w00t</item>
            </tags>
        </entry>
    </all-tags>

I’ve run this locally and it’s correctly selecting all the distinct items. What does yours output?

I think you’re really close. The problem I think is that following::item isn’t looking at the next items in the entire loop, but the next item node in relation to the current node. Maybe.

I used a similar method recently, as follows:

all-tags/entry/tags/item[not(.=preceding-sibling::all-tags/entry/tags/item)]

Sorry to bring back an old topic, but I never could get this code to work and now I’ve run into the problem again. Does this code work for you guys? I’ve checked it a few times and tried to read up on xsl’s “preceding-sibling”, but still having trouble.

Is the only other way to do it a custom datasource? If I used the custom datasource, could I still filter the tags that are returned based on what “project” their connected to?

Thanks for the help, really appreciate these forums.

I’d use the Muenchian grouping method to group your entries by tag. This would ensure uniqueness of your tags based upon the current available entries - that’s how I do the monthly & tag-based archive listings on my personal site. It can be a bit of a pain to get your head around the first few times you use it (there’s no good documentation aside from Jeni’s site), but it’s more efficient than multi-tiered looping of your content.

Here’s the link: Grouping Using the Muenchian Method

I agree with Tony. I would use Muenchian method of grouping as well. Jeni Tennison’s site is the best to pull from. Also, after doing a quick Google search, I came up with the following links…

Ditto Allen. I ran your test case as you defined it initially and got only unique tag names. I added several tag names with duplicates and still got a unique list.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details