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...
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
<select> <xsl:for-eachselect="$currentPage/node [string(data [@alias='umbracoNaviHide']) = '1']"> <!-- FIRST SORT BY YEAR --> <xsl:sortselect="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:iftest="data [@alias = 'year'] != ./preceding-sibling::node[1]/data [@alias = 'year']"> <option><xsl:value-ofselect="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
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
<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
<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
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:
Personally, i would recommend the uComponents string function for removing the dupes
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
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
its removing the common ones and showing the rest
sorry if this is a silly question:
have you added the line to sort the years?
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 " "> ]>
<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>
hi max
glad you worked it out. i didn't even think of using keys - seems much more efficient
good job
is working on a reply...