Copied to clipboard

Flag this post as spam?

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


  • Ulla Skaanning 67 posts 97 karma points
    Dec 10, 2011 @ 19:21
    Ulla Skaanning
    0

    Complicated: select multiple nodes to display in a list using XSLT

    Hi

    I am making a site for someone who breeds and sells horses. On this site I have created a document type called "horse" which contains a number of properties to collect and display information about that particular horse. Each horse has its own node, and these nodes can be located under 1out of number of different parent nodes, such as: "Horses for sale", Horses Sold", "Competing horses" etc.

    I would like to maintain that each horse only has 1 node so that you will not need to update it's information in more than one place. However, some of the horses are used for breeding, which means that some of the horses are also the parents of some of the other horses.

    Now here's the problem:

    For the horses used for breeding I need to show a list of their offspring when the user is viewing the details of that horse, preferably with a link to the node for each foal in the list.

    So I want my EDITOR to be able to select the nodes of all that horses 'children' and then use these selected nodes to display a list of the 'children'.

    Honestly I have NO idea what is the best way to do this, I'm hoping some of you guys have some suggestions.

    BTW I'm using v. 4.7.0

    Cheers Ulla

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 10, 2011 @ 19:50
    Jan Skovgaard
    1

    Hi Ulla

    I'm thinking you should add a content picker property on the horse document type (since the relation is 1-1), which you can use to select the parent horse.

    Then in your XSLT you can fetch the id with the umbraco.library:GetXmlNodeById() extension and then retrieve the information about the parent horse. It should'nt be too complicated to achieve what you're after then.

    Alternatively you can configure an instance of the ultimate picker where you can get the possible horses listed in a dropdown box on the content node - this also returns the id and the process in the XSLT will be the same...so I think you should go with the first mentioned option, unless you're client is liking the dropdown better than the content picker. It could be that the latter approach makes more sense to him/her.

    Let us know if you need some further explanation and XSLT examples to get you moving :)

    Hope this helps.

    /Jan

  • Rodion Novoselov 694 posts 859 karma points
    Dec 10, 2011 @ 21:55
    Rodion Novoselov
    1

    Hi. I would suggest changing the whole structure a bit. So that all horses would be in one single tree of parents and their offspring. Then turn the top level category ("Horses for sale", Horses Sold", "Competing horses" etc.) into a property (e.g. "Category") of the horse doctype (a drop-down list or a checkbox list). There'll be also additional profit that you will be able to let a horse to belong to several categories in case you implement this property as a checkbox list.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 11, 2011 @ 01:00
    Chriztian Steinmeier
    1

    Hi Ulla,

    If you've got uComponents installed (you should - it's an excellent set of good stuff for Umbraco), I'd highly suggest you use the Multi-Node Tree Picker for this - you can then create a property called "offspring", and allow only "horse" nodes to be picked. I wrote an article about using the Multi-Node Tree Picker in XSLT, that you can look at to get the info needed to get it working.

    /Chriztian

     

  • Ulla Skaanning 67 posts 97 karma points
    Dec 11, 2011 @ 15:57
    Ulla Skaanning
    0

    Hi guys

    Thanks for all of your great feedback - there's good stuff in all of your posts, so I've decided to do bit of a cocktail of al them. I have Installed uomponents - and I've got the Multiple-Node Tree Picker working on my Horse document Type. But the XSLT is causing me problems. I've called my Data Type:"SelectFoal"

    I've made an XLST and macro called "ListFoals" Which I have included on my Horse template. Ive tried modyfing the xslt from your article, but I'm a bit of a novice when it comes to XSLT - so it's not really working.

    My XSLT looks like this:

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>
        
    <xsl:key name="document-by-id" match="*[@isDoc]" use="@id" />

    <xsl:template match="/">
    <xsl:apply-templates select="$currentPage/SelectFoals" mode="multipicker" />
    </xsl:template>

    <xsl:template match="MultiNodePicker" mode="multipicker">
    <!-- Handle all the nodeIds in one go (!) -->
    <xsl:apply-templates select="key('document-by-id', nodeId)" />
    </xsl:template>

        

    <xsl:template match="Horse">
      <div class="horseBlock">  
        <div class="horsePicsmall">
        <xsl:choose>
            <xsl:when test="normalize-space(horsePic)">
                    <img src="{umbraco.library:GetMedia(horsePic, false())/umbracoFile}" />
            </xsl:when>
            <xsl:otherwise>
                    <img src="http://stutterigroenvang.com/css/pictures/EmptyImage.jpg" />
            </xsl:otherwise>
        </xsl:choose>
        </div> <!-- END horsePicsmall -->
        <div class="horseItemText">
          <h3 class="headline"> <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:value-of select="@nodeName"/></a>
          </h3>
          <p class="introduction">
              <xsl:value-of select="umbraco.library:ReplaceLineBreaks(introduction)" disable-output-escaping="yes"/>
          </p>
        </div><!-- END horseItemText -->
      </div><!-- END horseBlock -->

    </xsl:template>
       
    </xsl:stylesheet>

    At the bottom I've reused the XSLT that I originally made for displaying the offspring in a list - This might have to be remodelled a bit, but It contains most of the properties that I'd like to display in the list.

    However I'm convinced that the problems is that I'm not getting the data from the Picker right - Can you guys see what wrong?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Dec 11, 2011 @ 20:55
    Chriztian Steinmeier
    0

    Hi Ulla,

    It looks pretty good, actually - it's probably down to a typo or similar at this point; Check that the *property* on $currentPage actually has the alias "SelectFoals" (i.e.: The Umbraco GUI will try hard to name it "selectFoals" if you type "Select Foals" in the Name field, but it's still possible to override that).

    /Chriztian 

     

  • Ulla Skaanning 67 posts 97 karma points
    Dec 11, 2011 @ 21:49
    Ulla Skaanning
    0

    Hi Christian

    You just nailed it - that was exactly the problem :) I changed "SelectFoals" to "selectFoals" and it now works like a treat. Thanks so much for your help :)

    And btw. I also changed the strucure so that all the horses a now contained under the same parent note. I have then applied true/false checkboxes for wether the horse is in the breeding programme, for sale etc. Now I can call the horses into lists using XSLT, according to which checkboxes are checked. This is much easer for the Client to handle - so thank you to all of you :D

    Cheers Ulla :)

Please Sign in or register to post replies

Write your reply to:

Draft