Copied to clipboard

Flag this post as spam?

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


  • Touhid 97 posts 117 karma points
    Dec 08, 2010 @ 07:33
    Touhid
    0

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

     

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Dec 08, 2010 @ 10:12
    Michael Latouche
    0

    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.

  • Touhid 97 posts 117 karma points
    Dec 08, 2010 @ 10:35
    Touhid
    0

    thanks for response. now im doing that.

    touhid

  • Touhid 97 posts 117 karma points
    Dec 08, 2010 @ 12:02
    Touhid
    0

    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

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Dec 08, 2010 @ 12:16
    Michael Latouche
    0

    Hi Touhid,

    Strange indeed. Do you get the same behaviour if you display the node name instead of the "year" property?

    Cheers,

    Michael.

  • Touhid 97 posts 117 karma points
    Dec 08, 2010 @ 12:24
    Touhid
    0

    thanks, when i use:

     <xsl:value-of select="@nodeName" /> 

    then it shows the node name but i want to display the 1900 year.

    Touhid

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Dec 08, 2010 @ 13:23
    Michael Latouche
    0

    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.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 08, 2010 @ 13:54
    Tom Fulton
    0

    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:

               <xsl:value-of select="./year"/>       

    See these wiki articles for more info:  4.5 XML Schema  and  XSLT Examples updated to New Schema

  • Touhid 97 posts 117 karma points
    Dec 08, 2010 @ 14:38
    Touhid
    0

    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

     

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Dec 08, 2010 @ 14:54
    Michael Latouche
    0

    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.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 08, 2010 @ 14:54
    Tom Fulton
    0

    You can use a key to show only unique items, like so:

    Put this above your <xsl:template> tag

    <xsl:key name="year" match="* [@isDoc]" use="year"/>

    And change your for loop to:

    <xsl:for-each select="$currentPage/* [@isDoc][generate-id() = generate-id(key('year', ./year)[1])]">

    This should do the trick.

    And to answer what might be your next question, you can sort the years like so :)

    <xsl:sort select="year" data-type="number" order="ascending" />
  • Touhid 97 posts 117 karma points
    Dec 09, 2010 @ 07:05
    Touhid
    0

    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 "&#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: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

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Dec 09, 2010 @ 09:54
    Michael Latouche
    0

    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.

  • Touhid 97 posts 117 karma points
    Dec 09, 2010 @ 10:12
    Touhid
    0

    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

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Dec 09, 2010 @ 10:34
    Michael Latouche
    0

    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:

    <select name="yearselection" onchange="loadPage(this.form.elements[0])" target="_parent._top" >
    <option selected="selected">– Please select –</option>
     <option value="/History/hist1.aspx">1900</option>
     <option value="/History/hist2.aspx">2000</option>
    </select>

    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

  • Touhid 97 posts 117 karma points
    Dec 09, 2010 @ 11:54
    Touhid
    0

    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 "&#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: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

  • Michael Latouche 504 posts 819 karma points MVP 3x c-trib
    Dec 09, 2010 @ 12:41
    Michael Latouche
    0

    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):

    <xsl:variable name="selectedYear" select="umbraco.library:Request('ctrlCategory')" />
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <!-- start writing XSLT -->
    <xsl:if test="selectedYear != '' ">
        <xsl:for-each select="$currentPage/* [@isDoc][./year = selectedYear]">
             <h1><xsl:value-of select="./header"/></h1>

    <xsl:value-of select="./text"/>

        </xsl:for-each>
    </xsl:if>
     </xsl:template>

    Hope this helps and that my xslt is not too ugly ;-)

    Cheers,

    Michael.

Please Sign in or register to post replies

Write your reply to:

Draft