Copied to clipboard

Flag this post as spam?

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


  • Palle Hansen 143 posts 396 karma points
    Jun 13, 2016 @ 05:40
    Palle Hansen
    0

    How to get distinct values

    Hi, I'm struggling with an xslt that is suppose to give me some distinct values that I'm gonna use as options in a select.

    Here is what I've got:

    <xsl:variable name="make" select="umbraco.library:Request('make')"/>        
    <xsl:variable name="alldata" select="umbraco.library:GetXmlNodeById(1674)/Leasingcar"/>
    <xsl:variable name="prods" select="msxml:node-set($alldata) [wwleasingform/MultiNodePicker/nodeId = $make]" />
    
    <xsl:for-each select="msxml:node-set($prods) ">     
            <xsl:if test="generate-id() = generate-id(msxml:node-set($prods)[. = current()][1])">
                <option value="{wwbilmaerke}">
                    <xsl:value-of select="umbraco.library:GetXmlNodeById(wwbilmaerke)/@nodeName"/>
                </option>
         </xsl:if> 
    </xsl:for-each>
    

    The for-each gives me : Mercedes, BMW, BMW, Audi and it should give me Mercedes, BMW, Audi

    So I guess someting in the for-each isn't right.

    Can someone see what I'm doing wrong?

    Best regards Palle

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jun 13, 2016 @ 06:10
    Jan Skovgaard
    0

    Hi Palle

    I think you're missing a key in the above code - See the example by Tommy here http://blackpoint.dk/umbraco-workbench/xslt/grouping--distinct-values.aspx?p=3

    Perhaps you can also find further inspiration in this thread https://our.umbraco.org/forum/developers/xslt/4482-xslt-distinct - Only be aware that since these examples where created the XML schema of Umbraco changed - So if you see "node/data[@alias ='something']" a lot, which was the old way to do the XSLT back then. Just mentioning so you don't get confused by it :)

    Hope this helps!

    /Jan

  • Palle Hansen 143 posts 396 karma points
    Jun 14, 2016 @ 14:03
    Palle Hansen
    1

    Hi Jan.

    Thanks, it' helped You were right. Got it to work with this:

    <xsl:key name="lcars" match="leasingcar" use="."/>
    

    Palle

Please Sign in or register to post replies

Write your reply to:

Draft