Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    Oct 19, 2010 @ 19:45
    Kasper Dyrvig
    0

    jQuery tools scrollable - can it be done?

    Here is one I can't figure out my self...

    I want to create a list of 'cases' on a website. The cases are subpages for the page that is planned to view list. They are build from the document type "Case". The special about this document type is that it contains an uploaded thumbnail for the specific case. I have created this list, but I would like to have it like the jQuery Tools Scrollable minimal setup (see it here).

    My current xslt code is:

    <xsl:if test="$currentPage/@id = '1063' or $currentPage/@parentID = '1063'">
        <ul class="listCases">
          <xsl:for-each select="umbraco.library:GetXmlNodeById('1063')//Case [@isDoc]">
            <xsl:variable name="thisId" select="./@id"/>
            <li>
              <a title="{./@nodeName}">
                <xsl:attribute name="href">
                  <xsl:value-of select="umbraco.library:NiceUrl($thisId)"/>
                </xsl:attribute>
                <xsl:if test="$currentPage/@id = $thisId">
                  <xsl:attribute name="class">
                    <xsl:value-of select="'currentCase'"/>
                  </xsl:attribute>              
                </xsl:if>
                <xsl:choose>
                  <xsl:when test="./caseImage != ''">
                    <img alt="{./@nodeName}">
                      <xsl:attribute name="src">
                        <xsl:value-of select="umbraco.library:GetMedia(./caseImage, 0)/umbracoFile"/>
                      </xsl:attribute>
                    </img>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="./@nodeName"/>
                  </xsl:otherwise>
                </xsl:choose>
              </a>
            </li>
          </xsl:for-each>
        </ul>
      </xsl:if>

     

    But when it gets to making the scrollable list I guess (made from the example in the link above) that it should look more like this:

     <xsl:if test="$currentPage/@id = '1063' or $currentPage/@parentID = '1063'">
        <a class="prev browse left"></a>
        <div class="scrollable">
          <div class="items">
            <xsl:for-each select="umbraco.library:GetXmlNodeById('1063')//Case [@isDoc]">
              <xsl:variable name="thisId" select="./@id"/>
              <xsl:if test="position() = '0'">
                <xsl:text>&lt;div></xsl:text>
              </xsl:if>
                <!--Up to 5 links and images here-->
              <xsl:if test="position() = '5'">
                <xsl:text>&lt;/div></xsl:text>
              </xsl:if>
            </xsl:for-each>
          </div>
        </div>
        <a class="next browse right"></a>
      </xsl:if>

    So the trick is that for every five cases (subpages) they should be wrapped in a div, but also if there are e.g. 7 cases (5+2) the last 2 should also be wrapped in a div.

    Can someone help with that?

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 20, 2010 @ 19:28
    Kasper Dyrvig
    0

    I would still like some help with this...

  • Jonas Eriksson 930 posts 1825 karma points
    Oct 20, 2010 @ 22:28
    Jonas Eriksson
    1

    Hi!

    I'm sure some of the more Xslt-skilled Umbracians can answer your question - and I'd like to see the answer too. But I'd suggest you to ask it at Stackoverflow aswell for a quick answer if you dont get it here soon enough (bigger forum - quick responses, and your question is applicable outside of Umbraco). If you do and get the answer there - please post it back here aswell :-)

    Regards

    Jonas

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Oct 20, 2010 @ 22:46
    Peter Duncanson
    2

    Should be possible, I think you need to do a little juggling of what you have though but you are not far off. Try something like this instead:

        <xsl:if test="$currentPage/@id = '1063' or $currentPage/@parentID = '1063'">
          <a class="prev browse left"></a>
          <div class="scrollable">
            <div class="items">
              <xsl:for-each select="umbraco.library:GetXmlNodeById('1063')//Case [@isDoc]">
                <xsl:variable name="thisId" select="./@id"/>
                <!-- open your first div, we will only do it this once -->
                <xsl:if test="position() = first()">
                  <!-- bit dirty this bit but it will work -->
                  <xsl:text>&lt;div></xsl:text>
                </xsl:if>
    
                <!--Up to 5 links and images here-->
    
                <xsl:choose>
                  <xsl:when test="position() = last()">
                    <!-- just close your last div, as this is top of the choose statement none of the others will run so it should be safe to assume we are at the end -->
                    <xsl:text>&lt;/div></xsl:text>
                  </xsl:when>
                  <xsl:when test="position() mod 5 = 0">
                    <!-- close our open div -->
                    <xsl:text>&lt;/div></xsl:text>
                    <!-- open a new one -->
                    <xsl:text>&lt;div></xsl:text>
                  </xsl:when>
                </xsl:choose>
              </xsl:for-each>
            </div>
          </div>
          <a class="next browse right"></a>
        </xsl:if>

    Not checked it though so might need a little bit of work ;)

    Let me know if you have any problems or if it works

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 21, 2010 @ 00:12
    Chriztian Steinmeier
    2

    Hi Webspas (+ Pete & Jonas),

    Here's the unified and very XSLT way of doing stuff like this - which is also pretty much exactly how you'd do the much-coveted "group-to-table" problem, without resorting to PHP/ASP-like "cheating" (I'm kidding, of course :-)

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:make="urn:schemas-microsoft-com:xslt"
        xmlns:umbraco.library="urn:umbraco.library"
        exclude-result-prefixes="umbraco.library make"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="root" select="$currentPage/ancestor-or-self::root" />
    
        <!-- Size of group -->
        <xsl:variable name="groupsize" select="5" />
    
        <!-- Grab the data to output -->
        <xsl:variable name="nodes">
            <xsl:copy-of select="$root//*[@id = 1063]//Case" />
            <!-- You can do more complex stuff - e.g., pre-sorting the lot, if necessary -->
        </xsl:variable>
        <!-- Enable XPath selection in nodes -->
        <xsl:variable name="data" select="make:node-set($nodes)" />
    
        <xsl:template match="/">
            <a class="prev browse left"></a>
            <div class="scrollable">
                <div class="items">
                    <!-- Apply templates to every Nth document, starting with the first  -->
                    <xsl:apply-templates select="$data/*[position() mod $groupsize = 1]" mode="group" />
                </div>
            </div>
            <a class="next browse right"></a>
        </xsl:template>
    
        <!-- Template to start a group -->
        <xsl:template match="Case" mode="group">
            <div>
                <!-- Now render this document and the following to a total of N -->
                <xsl:apply-templates select=". | following-sibling::Case[position() &lt; $groupsize]" mode="item" />
            </div>
        </xsl:template>
    
        <!-- Template for a Case -->
        <xsl:template match="Case" mode="item">
            <div>
                <!-- Get creative... -->
                <xsl:value-of select="@nodeName" />
            </div>
        </xsl:template>
    
    </xsl:stylesheet>
    

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 21, 2010 @ 08:25
    Kasper Dyrvig
    0

    Thank you all for your replies!

    Chriztian - you rock with xslt! There is one bug... The output is:

    <a class="prev browse left">
    </a><div class="scrollable">
    <a class="prev browse left"> </a><div class="items">
    <a class="prev browse left"> </a><div>
    <a class="prev browse left"> </a><div><a class="prev browse left">Apple iPod</a></div>
    <a class="prev browse left"> </a><div><a class="prev browse left">Microsoft Zune</a></div>
    <a class="prev browse left"> </a></div>
    <a class="prev browse left"> </a></div>
    </div>
    <a class="next browse right"></a>

    As you can see the link with class "prev browse left" is represented a little too much...

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 21, 2010 @ 10:40
    Chriztian Steinmeier
    0

    Hi Webspas,

    When debugging XSLT output you have to look at the actual output (view-source) and not the DOM generated by the browser (you're seeing this in Firebug/Web Inspector).

    I was assuming you were filling the prev/next links with some text too - if you don't, the processor will output self-closing anchors (<a />) - a topic for another day :-)

    Try putting some text in the anchors and see what happens (alternately, you can put an epty comment in there - <xsl:comment /> to fix it)

    /Chriztian

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 21, 2010 @ 12:27
    Kasper Dyrvig
    0

    Of cause... doh!

    Well, thank you very much! I don't have the time to test is right now, but I'll let you know how it turns out.

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 22, 2010 @ 13:07
    Kasper Dyrvig
    0

    Yeay! It works!

Please Sign in or register to post replies

Write your reply to:

Draft