show content when select a year from dropdown list
hi,
im in great problem and i cant solve any way.
In my content section i have History page and also subpages its.like that:
History
-1900
-1910
-1920 etc.
here each subpages has content .
now, i want to a dropdownlist history page which contain the year and select a year and shows the content selected year. is it possible. can any one help me as soon as possible??
It describes how to build a dropdownlist for language selectionn on a multi-lingual site, but I think the xslt example can be adapted without too much difficulty to your situation.
Mmh this is strange indeed... Maybe you can check that the alias is spelled correctly in the backend? Did you re-publish the nodes after you specified the year value?
It looks like you are mixing the new and old schemas. If you are running 4.5+ and have a field called with the alias 'year' on your doctype, the code should this instead:
I assume this means that you have several nodes with year = 1900 under your History node? If this is the case, then displaying only one 1900 will lead to another problem: to which of the 1900 subnodes do you need to link to?
So my guess is that the best way to handle this is to have only one child node for a specific year.
Thanks. it works, but now im facing another problem. In my content section looking as follows:
Now i want a drop down list which contain the year(1900,2000), which has done. but when i select the year 1900 from dropdown list it will show the hist1 and hist3 content together in a page. I cant not solve it. can you help me ??
I think posting the content of the loadPage might help find out the problem.
In any case, I think the main issue in your example is that you have 2 nodes, "hist1" and "hist3" that are referenced by a single entry in your dropdown. So when selecting the option 1900, there is no way for the system to know which of the two nodes you actually need to display. Or, apparently, it does a mix of the two. Have you looked at the generated HTML content for the dropdown? I am wondering what is the option value for the "1900" option.
Maybe if you post the content of the loadPage function + HTML of the dropdown it will help find the solution.
Sorry, I did not express myself correctly. What I meant is, if from the browser you look at the HTML source generated when opening your history page, you should then see the HTML code that was rendered by the xslt engine to populate the actual dropdown markup in HTML language.
It's that part that would be inetersting to see because I am wondering which value is will use for the "1900" option since you have two nodes that match.
Unfortunately my knowledge of xslt is not very wide - yet (I'm more at the Asp .Net side of things), so I can't help you muche further on the xslt path.
But I think I just understood that you actually want to display all content of 1900 one under the other, and not see each page separately (sorry for misunderstanding...). In that case, I think your dropdown options values should not be the URL of the node, but the actual year value.
I would then include another xslt macro on your history.aspx page (or add extra xslt code right after your </form> in the same template, but it is less flexible I think), that would get the selected value as parameter, would loop through child nodes matching the year, and display the content. The parameter would come from the querystring/post parameters, like in your example. So, something like this (not tested and not guaranteed to work):
show content when select a year from dropdown list
hi,
im in great problem and i cant solve any way.
In my content section i have History page and also subpages its.like that:
History
-1900
-1910
-1920 etc.
here each subpages has content .
now, i want to a dropdownlist history page which contain the year and select a year and shows the content selected year. is it possible. can any one help me as soon as possible??
Hello,
You might have a look at the following page: http://www.nibble.be/?p=32
It describes how to build a dropdownlist for language selectionn on a multi-lingual site, but I think the xslt example can be adapted without too much difficulty to your situation.
Cheers,
Michael.
thanks for response. now im doing that.
touhid
hi it is working but there is a small problem.
dropdown doesnt show its value. i used a year which type is textstring.like that:-
year:1900
the dropdown does not show 1900 but a blank space is shows and when i click on blank space then it will work.
my problem is why it blank?? and my xslt is:
<form>
<select name="yearselection" onchange="loadPage(this.form.elements[0])" target="_parent._top" >
<option selected="selected">– Please select –</option>
<xsl:for-each select="$currentPage/* [@isDoc]">
<option value="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="data [@alias ='year']"/>
</option>
</xsl:for-each>
</select>
</form>
im waiting for ur reply.
touhid
Hi Touhid,
Strange indeed. Do you get the same behaviour if you display the node name instead of the "year" property?
Cheers,
Michael.
thanks, when i use:
<xsl:value-of select="@nodeName" />
then it shows the node name but i want to display the 1900 year.
Touhid
Mmh this is strange indeed... Maybe you can check that the alias is spelled correctly in the backend? Did you re-publish the nodes after you specified the year value?
Cheers,
Michael.
It looks like you are mixing the new and old schemas. If you are running 4.5+ and have a field called with the alias 'year' on your doctype, the code should this instead:
See these wiki articles for more info: 4.5 XML Schema and XSLT Examples updated to New Schema
Thanks it works. But i have another problem. that is like that:
Year:
-1900
-2000
-2010
-1900
Which contain some year many time , but i need only one 1900 year. so how can this solve?
Touhid
Hello,
I assume this means that you have several nodes with year = 1900 under your History node? If this is the case, then displaying only one 1900 will lead to another problem: to which of the 1900 subnodes do you need to link to?
So my guess is that the best way to handle this is to have only one child node for a specific year.
Cheers.
Michael.
You can use a key to show only unique items, like so:
Put this above your <xsl:template> tag
And change your for loop to:
This should do the trick.
And to answer what might be your next question, you can sort the years like so :)
Thanks. it works, but now im facing another problem. In my content section looking as follows:
Now i want a drop down list which contain the year(1900,2000), which has done. but when i select the year 1900 from dropdown list it will show the hist1 and hist3 content together in a page. I cant not solve it. can you help me ??
I used a macro for year dropdown :
<?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:key name="year" match="* [@isDoc]" use="year"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<!-- start writing XSLT -->
<form>
<select name="yearselection" onchange="loadPage(this.form.elements[0])" target="_parent._top" >
<option selected="selected">– Please select –</option>
<xsl:for-each select="$currentPage/* [@isDoc][generate-id() = generate-id(key('year', ./year)[1])]">
<option value="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="./year"/>
</option>
</xsl:for-each>
</select>
</form>
</xsl:template>
</xsl:stylesheet>
Touhid
Hi Touhid,
I think posting the content of the loadPage might help find out the problem.
In any case, I think the main issue in your example is that you have 2 nodes, "hist1" and "hist3" that are referenced by a single entry in your dropdown. So when selecting the option 1900, there is no way for the system to know which of the two nodes you actually need to display. Or, apparently, it does a mix of the two. Have you looked at the generated HTML content for the dropdown? I am wondering what is the option value for the "1900" option.
Maybe if you post the content of the loadPage function + HTML of the dropdown it will help find the solution.
Cheers,
Michael.
Thaks for reply. hey Michael im new umbraco so dont mind. here is the loadpage function which i used in History template:
<%@ Master Language="C#" MasterPageFile="~/masterpages/Master.master" AutoEventWireup="true" %>
<asp:content ContentPlaceHolderId="MainContent" runat="server">
<script language="JavaScript">
function loadPage(list)
{
location.href=list.options[list.selectedIndex].value
}
</script>
<umbraco:Macro Alias="History" runat="server"></umbraco:Macro>
</asp:Content>
And i have no used HTML for dropdown.Instead of HTML i used that:
<xsl:for-each select="$currentPage/* [@isDoc][generate-id() = generate-id(key('year', ./year)[1])]">
<option value="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="./year"/>
</option>
</xsl:for-each>
Touhid
Hi Touhid,
Sorry, I did not express myself correctly. What I meant is, if from the browser you look at the HTML source generated when opening your history page, you should then see the HTML code that was rendered by the xslt engine to populate the actual dropdown markup in HTML language.
So, something like:
It's that part that would be inetersting to see because I am wondering which value is will use for the "1900" option since you have two nodes that match.
Cheers,
Michael
Sorry. Mike i cant solve it. so i choose another way: look the folowing xslt.
<?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:key name="year" match="* [@isDoc]" use="year"/>
<xsl:variable name="year" select="umbraco.library:Request('ctrlYear')" />
<xsl:param name="currentPage"/>
<xsl:template match="/">
<!-- start writing XSLT -->
<form name="myForm" action="{umbraco.library:NiceUrl($currentPage/@id)}" method="post">
<select name="ctrlCategory" onchange="document.myForm.submit()">
<option selected="selected">– Please select –</option>
<xsl:for-each select="$currentPage/* [@isDoc][generate-id() = generate-id(key('year', ./year)[1])]">
<option value="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="year"/>
</option>
</xsl:for-each>
</select>
</form>
</xsl:template>
</xsl:stylesheet>
Now, can you tell me how to call another template using same page (history.aspx) within this xslt file or is it possible??
Touhid
Hi Touhid,
Unfortunately my knowledge of xslt is not very wide - yet (I'm more at the Asp .Net side of things), so I can't help you muche further on the xslt path.
But I think I just understood that you actually want to display all content of 1900 one under the other, and not see each page separately (sorry for misunderstanding...). In that case, I think your dropdown options values should not be the URL of the node, but the actual year value.
I would then include another xslt macro on your history.aspx page (or add extra xslt code right after your </form> in the same template, but it is less flexible I think), that would get the selected value as parameter, would loop through child nodes matching the year, and display the content. The parameter would come from the querystring/post parameters, like in your example. So, something like this (not tested and not guaranteed to work):
Hope this helps and that my xslt is not too ugly ;-)
Cheers,
Michael.
is working on a reply...