Copied to clipboard

Flag this post as spam?

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


  • Frederik T 241 posts 372 karma points
    Aug 15, 2011 @ 09:57
    Frederik T
    0

    List of all documents from all descendant pages.

    Since my original post about this subject didnt get any replies, as due to misleading title, and not being able to change it, i feel that i need to create a new topic, as this is a pressing issue and i am sorry if i infringed any forum rules.

    The thing is, the site im working on as several sub sections, and those have sub sections as well.

    -Main
    ---section1
    ......section1,1
    ......section1,2
    ---section2
    ......section2,1
    ---section3

    Sorta like that. Each sub-sub section (like section1,2) has several articles/documents in them. Each section has their own unique document type, but they inherit from the same parent document.

    In for example section 1, i have to make a list of all the newest articles in each sub section (section 1,1/1,2 in above tree example)

    Now starts the hairy part, this is what ive come up with as of now:

    <xsl:variable name="documentTypeAlias1" select="string('documentType1')"/>
    <xsl:variable name="documentTypeAlias2" select="string('documentType2')"/>
    <xsl:variable name="documentTypeAlias3" select="string('documentType3')"/>

    <xsl:template match="/">

    <
    ul>
    <xsl:for-each select="$currentPage/descendant::* [name() = $documentTypeAlias1 or name() = $documentTypeAlias2 and string(umbracoNaviHide) != '1']">
      <xsl:sort select="@updateDate" order="descending" />
      <li>
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
         
          <xsl:if test="count(current()/outputPictures) > 0">
            <img src="/ImageGen.ashx?image={current()/outputPictures[position()=1]/DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&amp;width=125&amp;height=70"
     
    width="125" height="70"/>
          </xsl:if>
         
        </a>
      </li>
    </xsl:for-each>
    </ul>

    (the variable names are example names for the sake of this post, company policy you know)

    This creates a list of the specified document types, orders them, then shows the first picture in its gallery as a thumbnail.

    It works, somewhat, because first of all, its outright stupid doing it the way i am, storing document types in variables and stuffing them into the select, also it orders them by the document type (as in, it displays the newest document type and its related articles, to the oldest, if you understand), and not the speciefic documents updateDate. But i dont know of any other way.

    Therefor, i thought it would be possible to just make it list ALL document types under that section and sub sections, inheriting from the parent document type. But i dont know how to.

    I hope it makes sense, and maybe there is an entirely other method.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 15, 2011 @ 23:52
    Chriztian Steinmeier
    1

    Hi Frederik,

    I'm not completely sure I understand what you mean by "inherit from the same parent document" but I assume you're referring to the fact that they are descending from the same doc...

    But I thought I'd squash a few of your problems by refactoring your code to something a little more XSLT'ish, if you don't mind:

    <xsl:template match="/">
        <ul>
            <!-- Process ALL descendants of $currentPage -->
            <xsl:apply-templates select="$currentPage/descendant::*[@isDoc][not(umbracoNaviHide = 1)]">
                <xsl:sort select="@updateDate" data-type="text" order="descending" />
            </xsl:apply-templates>
        </ul>
    </xsl:template>
    
    <!-- Template for specific DocumentTypes -->
    <xsl:template match="documentType1 | documentType2 | documentType3">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName" />
    <!-- Take first image (if any) -->
                <xsl:apply-templates select="outputPictures[1]" />
            </a>
        </li>
    </xsl:template>
    
    <!-- Template for thumbnail image -->
    <xsl:template match="outputPictures">
        <img src="/ImageGen.ashx?image={DAMP[@fullMedia]/mediaItem/Image/umbracoFile}&amp;width=125&amp;height=70" width="125" height="70" />
    </xsl:template>
    
    <!-- Template for all non-matched DocumentTypes -->
    <xsl:template match="*[@isDoc]" priority="-1">
        <!-- Suppress output... -->
    </xsl:template>
    
    Note that you don't need to define string variables for the Doctypes and that you do not need to count the number of outputPictures children to determine if there are any...

    /Chriztian 

  • Frederik T 241 posts 372 karma points
    Aug 16, 2011 @ 09:16
    Frederik T
    0

    Thank you for your reply. I know my title is very likely misleading, i apologize for that, seeing as im both new to umbraco and english isnt my first language, its difficult to convey my problems.

    The topic of my post points at a direction that likely isnt the problem per say, because it merely describes what i thought was the solution at the time, which is possible it isnt. Like i described in my post, with the sections, i have a main page, with several sub section, and i need a list of the newest articles from all of the sub sections, hopefully limited to a specific number of listed items.

    Also, that last empty template that says "surpress output", should i leave that empty?

    But i will give your code a go and see how it works, i appreciate your help.

     

    (a quick note, is using templates "more xslt'ish"? what is the benefit? I ask out of curiosity as im still new at this)

     

    EDIT

    It works! Thank you very much! There are still some things to iron out, like i said, mostly because i dont know how templates work that you used in your code. If i should limit the amount of items listed, where do i put it? And the styling doesnt work very well, but i dont know the correct place to place the "class". But the styling is the least important right now as i can fix it (i think) when i learn about templates tag.

  • Frederik T 241 posts 372 karma points
    Aug 22, 2011 @ 10:12
    Frederik T
    0

    Sorry for bumping this, but there is an error, in addition to those described in my above post, that i need help with.

    I figured how to limit the number of items displayed in the list, but when i limit it, the order is different. I have a suspicion that i limit the amount of document types it lists and not just how many items is listed in general. If that makes sense? Either way, limiting doesnt really work, so i must be doing something wrong as i know its possible of course.
    I also have a feeling that, even if the xsl:template that was written above is very good, it might hinder me at trying to fix this problem, as i dont know how to use that function yet.

Please Sign in or register to post replies

Write your reply to:

Draft