Copied to clipboard

Flag this post as spam?

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


  • Dan 1250 posts 3747 karma points admin c-trib
    Feb 02, 2010 @ 13:51
    Dan
    0

    Display all distinct values of a field under node

    Hi,

    I have a structure like this:

    Gallery
    - Album 1
    --Image 1
    --Image 2
    --Image 3
    -Album 2
    - Image 4
    - Image 5
    - Image 6

    Each album document type contains a text field with an alias 'AlbumProject'.  What I want to do is pull all distinct values of 'AlbumProject' into a list.

    The code I have so far is:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1']//data [@alias = 'AlbumProject'] [not(.=preceding::data [@alias = 'AlbumProject'])]">
    <li>
    <xsl:value-of select=""/>
    </li>
    </xsl:for-each>

    Can anyone see how to wrap this up and get the value from the select into the list?

    Thanks all...

  • Dan 1250 posts 3747 karma points admin c-trib
    Feb 02, 2010 @ 14:10
    Dan
    0

    I've updated it to set the value of the select, but it returns nothing:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1']//data [@alias = 'AlbumProject'] [not(.=preceding::data [@alias = 'AlbumProject'])]">
    <li>
    <xsl:value-of select="current()/data [@alias = 'AlbumProject']"/>
    </li>
    </xsl:for-each>

    There's obviously something wrong with the first line here, in the way it's searching for the nodes.

  • Tommy Poulsen 514 posts 708 karma points
    Feb 02, 2010 @ 14:19
    Tommy Poulsen
    0

    Hi Dan, I think I would go for the key/id approach where you generate keys for identical values. Check out this page for more info - it's a bit hairy if you are not already familiar with keys and id's, but it is extremely powerful and fast

    http://blackpoint.dk/umbraco-workbench.aspx?Snippet=/umbraco-workbench/xslt/grouping--distinct-values.aspx

    >Tommy

     

  • Dan 1250 posts 3747 karma points admin c-trib
    Feb 02, 2010 @ 14:48
    Dan
    0

    Thanks Tommy, that's going to be a 'challenge' for my limited skills.  I'll certainly look into it though.  In the meantime, I can live without the 'distinct' part of the requirement, but even this doesn't return anything:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1']//data [@alias = 'AlbumProject']">
    <li>
    <xsl:value-of select="current()/data [@alias = 'AlbumProject']"/>
    </li>
    </xsl:for-each>

    Any ideas?

  • Dan 1250 posts 3747 karma points admin c-trib
    Feb 02, 2010 @ 15:54
    Dan
    0

    It's definitely something to do with this syntax:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node//data [@alias = 'AlbumProject']">

    How can I just select that specific data from the nodes?

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Feb 02, 2010 @ 16:19
    Nik Wahlberg
    0

    Hi Dan, should be something like this:

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [data [@alias = 'AlbumProject']]">
    HTH
    Nik

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Feb 02, 2010 @ 16:20
    Nik Wahlberg
    0

    Oh, and if you need help with the grouping, let me know and I can try to get you something for that...that will probably be your best approach for distinct output...

    Thanks,
    Nik

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Feb 02, 2010 @ 16:22
    Nik Wahlberg
    1

    Scratch my post.... here's what you are trying to do...

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1']">
           
    <li>
                   
    <xsl:value-of select="data [@alias = 'AlbumProject']"/>
           
    </li>
    </xsl:for-each>

    Sorry...

  • Dan 1250 posts 3747 karma points admin c-trib
    Feb 02, 2010 @ 16:30
    Dan
    0

    Thanks Nik.  It's looping through now (it outputs two list items and I know there are two album nodes, so that follows) but the values are empty, so it's just returning <li></li><li></li>.

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Feb 02, 2010 @ 16:51
    Nik Wahlberg
    0

    Can you confirm that the child nodes of the 'source' node in fact have that property? Is AlbumProject an property of a documentType or a documentType itself?

    Thanks,
    Nik 

  • Dan 1250 posts 3747 karma points admin c-trib
    Feb 02, 2010 @ 17:07
    Dan
    0

    The child nodes of the source node contain a text field with the alias 'AlbumProject'.

  • Dan 1250 posts 3747 karma points admin c-trib
    Feb 02, 2010 @ 17:09
    Dan
    0

    My bad!  Typo.  Thanks Nik, that's sorted the initial thing out - now I just need to get to grips with making it distinct.

  • Tommy Poulsen 514 posts 708 karma points
    Feb 02, 2010 @ 17:29
    Tommy Poulsen
    1

    Hi Dan

    If you wanna give the key/id approach a go, its something like this - out of my head:

    <xsl:key name="mykey" match="node" use="data [@alias = 'AlbumProject']"/>
    ...
    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1'] [generate-id() = generate-id(key('mykey', data [@alias = 'AlbumProject'])[1])]">
      <xsl:value-of select="data [@alias = 'AlbumProject']"/><br/>
    </xsl:for-each>

    - but I can try to test it out later if you cannot work it out.

    >Tommy

     

     

  • Dan 1250 posts 3747 karma points admin c-trib
    Feb 05, 2010 @ 16:58
    Dan
    0

    Thanks for this Tommy, I've now got the following:

    <xsl:key name="mykey" match="node" use="data [@alias = 'AlbumProject']"/>

    <xsl:template match="/">

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/node [string(data [@alias='umbracoNaviHide']) != '1'] [generate-id() = generate-id(key('mykey', data [@alias = 'AlbumProject'])[1])]">
    <option>
    <xsl:value-of select="data [@alias = 'AlbumProject']"/>
    </option>
    </xsl:for-each>

    </xsl:template>

    But it's not outputting anything.  Can you see a reason this isn't working?

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Feb 07, 2010 @ 00:28
    Chriztian Steinmeier
    1

    Hi Dan,

    There is at least one scenario where the above wouldn't produce any output: If the first of every possible AlbumProject value is placed on a hidden node.

    Could this be the case?

    Then you'd need to either:

    A: Include the umbracoNaviHide predicate in the key definition, like this:

    <xsl:key name="mykey" match="node[not(data[@alias = 'umbracoNaviHide'] = 1)]" use="data[@alias = 'AlbumProject']"/>

    or B: Exclude it from the select, and handle it inside the for-each statement instead:

    <xsl:for-each select="$source/node[generate-id() = generate-id(key('mykey', data[@alias = 'AlbumProject'])[1])]">
        <xsl:if test="not(data[@alias = 'umbracoNaviHide'] = 1)">
            <li>
                <xsl:value-of select="data[@alias = 'AlbumProject']"/>
            </li>
        </xsl:if>
    </xsl:for-each>
    
    /Chriztian
  • Tommy Poulsen 514 posts 708 karma points
    Feb 07, 2010 @ 11:37
    Tommy Poulsen
    0

    Hi Dan, do you get any output if you remove the generate-id clause

    [generate-id() = generate-id(key('mykey', data [@alias = 'AlbumProject'])[1])]

    ?

    >Tommy

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies