Copied to clipboard

Flag this post as spam?

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


  • anthony hall 222 posts 536 karma points
    Oct 06, 2009 @ 11:03
    anthony hall
    0

    xslt distinct

    if it possible to return distinct results. 

    ie

    <xsl:for-each select="$productCover/descendant::node [@nodeTypeAlias = 'productFabric']">

    if my @nodeName = "Linen" only show once

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 06, 2009 @ 11:12
    Dirk De Grave
    1

    Hi Anthony, that is possible, let me find that example...

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

     

    Cheers,

    /Dirk

  • dandrayne 1138 posts 2262 karma points
    Oct 06, 2009 @ 11:22
    dandrayne
    1

    bookmarked that link, cheers Dirk!

    This may also be possible using [not(.=following::ATTRIBUTE)]

    Here's a sample of something done in the past to ensure a unique list from node values (in this case, a list of area names, to form a dropdown with unique values).  The syntax is a bit lighter but might not work in all circumstances.  This might also help -> http://stackoverflow.com/questions/153156/xslt-how-to-count-distinct-values-in-a-node

    <xsl:variable name="myFeed" select="document('myFeed.xml')"  />
    <xsl:template match="/">

    <xsl:variable name="unique-list" select="$myFeed//Area[not(.=following::Area)]" />
    <select id="thearea" name="thearea">
    <option value="">All areas</option>
    <xsl:for-each select="$unique-list">
    <xsl:sort order="ascending" data-type="text" />
    <option value="{.}">
    <xsl:value-of select="." />
    </option>
    </xsl:for-each>
    </select>
    </xsl:template>
  • anthony hall 222 posts 536 karma points
    Oct 06, 2009 @ 12:19
    anthony hall
    0

    thanks, really interesting replies. 

    i'm trying out Dan's example. I have something like this.  I want to match by @nodeName.

    As you see "count($unique-list)" // returns 28

    But for some reason i can't foreach or get @nodeName from it.

    <xsl:variable name="productCover" select="$product/descendant::node [@nodeTypeAlias = 'productCover']"/> <xsl:variable name="unique-list" select="$productCover//nodeName[not(.=following::nodeName)]" />

    <xsl:value-of select="count($unique-list)"/> // returns 28 <xsl:for-each select="$unique-list/descendant::node [@nodeTypeAlias = 'productFabric']">

     

     

    Here is the xslt that show all results without "not"

    <xsl:variable name="productCover" select="$product/descendant::node [@nodeTypeAlias = 'productCover']"/>
    <xsl:for-each select="$productCover/descendant::node [@nodeTypeAlias = 'productFabric']">

     

  • anthony hall 222 posts 536 karma points
    Oct 06, 2009 @ 12:22
    anthony hall
    0

    sorry. i mean @nodeName

    <xsl:variable name="unique-list" select="$productCover//@nodeName[not(.=following::nodeName)]" />

  • dandrayne 1138 posts 2262 karma points
    Oct 06, 2009 @ 12:49
    dandrayne
    1

    Hmm.  The syntax will change when using attribute and note nodes.  I've just quickly tested the following code on a site I'm working on (searching for unique page headers), so give it a shot and let me know how you get on.

    This is what seemed to work for me.

    <xsl:variable name="unique-list" select="$currentPage//node/data[@alias='pageHeading' and not(.=following::node/data[@alias='pageHeading'])]" />

    So this may work for you

    <xsl:variable name="unique-list" select="$product//node/data[@alias='productCover' and not(.=following::node/data[@alias='productCover'])]" />

    Worth a shot! 

    I do with xslt2 was in umbraco,it would be as easy as

    count(distinct-values($NodeSet))

     

    Good luck,
    Dan

  • dandrayne 1138 posts 2262 karma points
    Oct 06, 2009 @ 12:49
    dandrayne
    0

    * "note nodes" = "not nodes"

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Oct 06, 2009 @ 12:59
    Douglas Robar
    1

    @Dan... you're right, XSLT 2.0 would be nice. But until then, don't forget the umbraco library and the EXSLT extensions built-in to umbraco. You can get distinct results with:

    <xsl:value-of select="Exslt.ExsltSets:distinct($nodeset)" />

    This will return a node-set fragment so depending on how you want to use the result you may need to use the msxsl:node-set() function to convert the output back to a full node-set.

    cheers,
    doug.

  • dandrayne 1138 posts 2262 karma points
    Oct 06, 2009 @ 13:06
    dandrayne
    1

    Sweet! I always overlook exslt. sets:distinct seems to do the trick exactly.  Bookmarked http://exslt.org/set/functions/distinct/index.html

    Cheers Doug

  • anthony hall 222 posts 536 karma points
    Oct 06, 2009 @ 21:09
    anthony hall
    0

    lots of options here. I've tried them all. Still no luck. 

    1) I tried dirk's http://blackpoint.dk/umbraco-workbench.aspx?Snippet=/umbraco-workbench/xslt/grouping--distinct-values.aspx">suggestion

    here's where i got. No results. 

    <xsl:key name="nodeMatch" match="node" use="@alias='selectFabric'"/> <xsl:template match="/"> <xsl:variable name="nodeset" select="$productCover/descendant::node [@nodeTypeAlias = 'productFabric'] "/>

    <xsl:for-each select="$nodeset/node[generate-id() = generate-id(key('nodeMatch', data[@alias='selectFabric'])[1])]"> <xsl:value-of select="data [@nodeName]"/> </xsl:for-each>

    2) Doug's Exslt.ExsltSets:distinct($nodeset)

    This gave me a parsing error. Is this really in use. It's not a very noisey keyword in the forums.


    3) Dan's not statement. I'm getting no results. 

    <xsl:variable name="nodeset" select="$productCover/descendant::node [@nodeTypeAlias = 'productFabric'] "/>
    <xsl:variable name="uniquelist" select="$nodeset/data[@alias='selectFabric' and not(.=following::node/data[@alias='selectFabric'])]" />
    <xsl:for-each select="$uniquelist">
    <xsl:value-of select="@nodeName"/>
    </xsl:for-each>

    anyway, really appreciate all the tips. 

    Anthony

     

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

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

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

     

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

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

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

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

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

  • dandrayne 1138 posts 2262 karma points
    Oct 06, 2009 @ 21:20
    dandrayne
    1

    Without getting into the keys thing (which I should read up on at some stage)

    2. You'll need to add the relevant headers to the xslt file to use exslt.  Here's the head of a file with all (i think) of the available headers, then just use it like in dougs suggestion

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    3.  Your syntax looks ok in the select statements, so I'd print out uniquelist before going through it. At the very least, it would be

    <xsl:for-each select="$uniquelist/node">

    but I'd copy it to the screen to see what it's made up of.

    <xsl:copy-of select="$uniquelist" />

     

    Good luck!
    Dan

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 06, 2009 @ 21:25
    Dirk De Grave
    1

    Anthony, to be honest never got it to work either unless I was working with a key of integer type, which is just not what I wanted. I ended up writing a user control and use c# to do the grouping and sorting.

    Doug's suggestion seems fine, altho not sure about the Exslt.ExsltSets:distinct($nodeset). Do you need the first 'Exslt'?

     

    Cheers;

    /Dirk

  • dandrayne 1138 posts 2262 karma points
    Oct 06, 2009 @ 21:31
    dandrayne
    1

    @dirk - I think so - to do a calendar recently (possibly part of a future project) I found that

    <xsl:variable name="DisplayDate" select="Exslt.ExsltDatesAndTimes:date()"/>

    Is what is needed to get it working. 

  • anthony hall 222 posts 536 karma points
    Oct 06, 2009 @ 21:48
    anthony hall
    0

    @dirk ah ok. Yeah might just have to c# it.

    @dan, really appreciate your help. I think it i was just dealing with $currentPage it might be easier to use your method. 

    For interest, here is the stack trace for Exslt.ExsltSets:distinct($nodeset). I added the correct xslt namespaces as suggested by dan.

    <xsl:if test="$nodeset!= ''">

    <xsl:value-of select="Exslt.ExsltSets:distinct($nodeset)" /> </xsl:if>


    Value cannot be null.
    Parameter name: type
    Value cannot be null.
    Parameter name: type
      at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
      at umbraco.presentation.xslt.Exslt.ExsltCommon.ExsltNodeListToXPathNodeIterator(ExsltNodeList list)
      at umbraco.presentation.xslt.Exslt.ExsltSets.distinct(XPathNodeIterator nodeset)

  • Kim Nedergaard 37 posts 144 karma points
    Jul 07, 2011 @ 16:51
    Kim Nedergaard
    0

    Hi

     

    I'm getting the same problem, anyone solved the riddle yet?

     

    -Kim

  • 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