Copied to clipboard

Flag this post as spam?

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


  • Max 144 posts 166 karma points
    Apr 04, 2011 @ 09:29
    Max
    0

    List items fields in a html dropdownlist

    Hi have  a document type where the user will input the year for e.g. 1975, 1999. 2007,2007 in textstring,  etc and other contents in child node content pages i want to create a html drop down list that will take all DISTINCT years form the child nodes contents for filtering and sortign data from the Root page...

    any code examples or technique will be useful

     

  • Fergus Davidson 309 posts 588 karma points
    Apr 04, 2011 @ 10:28
    Fergus Davidson
    0
    <xsl:template match="/">

    <xsl:variable name="src" select="$currentPage" />
      
      <xsl:variable name="yArr">
        <xsl:for-each select="$src/* [local-name()='newsArticle']">
          <xsl:sort select="umbraco.library:FormatDateTime(displayDate,'yyyy')" />
          
          <xsl:value-of select="umbraco.library:FormatDateTime(displayDate,'yyyy')" />,
        xsl:for-each>
      xsl:variable>
      <xsl:variable name="uniqueYears" select="ucomponents.strings:RemoveDuplicateEntries($yArr,',')" />

      <select>
        <option value="*">select a yearoption>
        <xsl:for-each select="umbraco.library:Split($uniqueYears)/value" >
          <option value="{.}"><xsl:value-of select="." />option>
        xsl:for-each>
      select>
    xsl:template>

     

    the above should do something like you are asking, but is untested. 

    EDIT: it obviously relies on one of the uComponents string functions to remove any duplicate entries

  • Max 144 posts 166 karma points
    Apr 04, 2011 @ 11:41
    Max
    0

    <select>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) = '1']">
        <!--<li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>-->

      <option><xsl:value-of select="data [@alias = 'year']"/></option>
     

    </xsl:for-each>
    </select>

    her eis my code i get al years bu ti need to get distict Year liek no repeat of Years

     

  • Fergus Davidson 309 posts 588 karma points
    Apr 04, 2011 @ 11:52
    Fergus Davidson
    0

    Max, you could load all the years into a variable and then unique-ify them as in my code above, or you could possibly extend yours by sorting by year, looping through and only adding the year if it is different from the previous one.

    Something like again, this is untested:

    <select>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) = '1']">
    <!-- FIRST SORT BY YEAR -->
    <xsl:sort select="data [@alias = 'year']" />
        <!--<li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>-->
    <!-- ONLY INSERT IF THE YEAR IS NOT THE SAME AS THE PREVIOUS -->
    <xsl:if test="data [@alias = 'year']  !=  ./preceding-sibling::node[1]/data [@alias = 'year']">
      <option><xsl:value-of select="data [@alias = 'year']"/></option>
    </xsl:if>
    
    
    </xsl:for-each>
    </select>

    Personally, i would recommend the uComponents string function for removing the dupes

  • Pasang Tamang 258 posts 458 karma points
    Apr 04, 2011 @ 11:53
    Pasang Tamang
    0

    Hi Max,

    Better you should write some custom xsltextension using .net coding which gives you distinct values. You may follow this example http://our.umbraco.org/forum/developers/api-questions/18836-Media-?p=1

    Pnima

  • Max 144 posts 166 karma points
    Apr 04, 2011 @ 12:40
    Max
    0
    <select>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) = '1']">
    <!-- FIRST SORT BY YEAR -->
    <xsl:sort select="data [@alias = 'year']" />
       
    <!--<li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>-->

    <!-- ONLY INSERT IF THE YEAR IS NOT THE SAME AS THE PREVIOUS -->
    <xsl:if test="data [@alias = 'year']  !=  ./preceding-sibling::node[1]/data [@alias = 'year']">
     
    <option><xsl:value-of select="data [@alias = 'year']"/></option>
    </xsl:if>
     

    </xsl:for-each>
    </select>

    this one works fine but it gets rid of the common Years like if i have 2 years 1975 , and another ndoe 1975 i want to show ontl 1
    this one gets rid of that one and shows the rest
  • Fergus Davidson 309 posts 588 karma points
    Apr 04, 2011 @ 12:59
    Fergus Davidson
    0

    hi max

    sorry, i am not sure i understand your comment:

    are you saying that this is not deduping the years correctly, that it is removing the first one and showing the rest?

    thanks

  • Max 144 posts 166 karma points
    Apr 04, 2011 @ 13:03
    Max
    0
    its removing the common ones and showing the rest 

  • Fergus Davidson 309 posts 588 karma points
    Apr 04, 2011 @ 13:05
    Fergus Davidson
    0

    sorry if this is a silly question:

    have you added the line to sort the years?

    <xsl:sort select="./data [@alias = 'year']" />

  • Max 144 posts 166 karma points
    Apr 04, 2011 @ 20:25
    Max
    1

    its DONE i did it here is the code Just for the reference

     

    <?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 ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
    <xsl:key  name="MyKey" match="node" use="data [@alias = 'year']"/>

    <xsl:template match="/">


    <!-- The fun starts here  $currentPage-->
    <select>
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) = '1' ][generate-id() = generate-id(key('MyKey', data [@alias = 'year'])[1])]">
        <!--<li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>-->

     
     <!-- <option><xsl:value-of select="data [@alias = 'year'] [not(.=preceding::data [@alias = 'year'])]"/></option>-->

     <option><xsl:value-of select="data [@alias = 'year']"/></option>
     
     

    </xsl:for-each>
    </select>

    </xsl:template>

    </xsl:stylesheet>

     

  • Fergus Davidson 309 posts 588 karma points
    Apr 05, 2011 @ 20:53
    Fergus Davidson
    0

    hi max

    glad you worked it out. i didn't even think of using keys - seems much more efficient

    good job

Please Sign in or register to post replies

Write your reply to:

Draft