Copied to clipboard

Flag this post as spam?

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


  • Patrick 23 posts 83 karma points
    Mar 15, 2012 @ 20:43
    Patrick
    0

    stuck in Xslt

    I have made the following structure.

    NodeX
      + Project
        - Items
        - Items
      + Project
        - Items
        - Items   

    Each project has a thumbnail and each item has two enlargements called large and largedetail.

    I want to generate a list of thumbnails to be displayed on NodeX.
    I also want to generate a list of the large items with a href (fancybox) on it which displays largedtail.

    The for-each loop isn't a problem, but displaying the different fields is.
    BTW, another question, does a for-each loop always loop in the order which is given on the backend?

    Any help is appreciated.

    Greetz, Patrick

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 15, 2012 @ 22:12
    Chriztian Steinmeier
    1

    Hi Patrick,

    To start at the bottom: You can shove a sort instruction inside a for-each to specify the sort order, e.g.:

    <xsl:for-each select="*">
        <xsl:sort select="@sortOrder" data-type="number" order="ascending" />
    
        <!-- Do something -->
    
    </xsl:for-each>

    In the sort's select attribute you can specify an XPath expression, which can be as simple as an attribute (as in this example) or a complex calculation.

    The best way to do something like this is actually to create a template for a single Project and instead of using for-each, use the apply-templates instruction - short sample here:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
        <xsl:variable name="projectsRoot" select="$siteRoot/Projects" /><!-- Select NodeX here -->
    
        <xsl:template match="/">
            <xsl:apply-templates select="$projectsRoot/Project">
                <xsl:sort select="@nodeName" data-type="text" order="ascending" />
            </xsl:apply-templates>
        </xsl:template>
    
        <xsl:template match="Project">
            <section class="project">
                <h1><xsl:value-of select="@nodeName" /></h1>
                <p>
                    Project details ...
                </p>
            </section>
        </xsl:template>
    
    </xsl:stylesheet>

    As you can see, the apply-templates instruction enables you to extract the Project markup (so it doesn't have to live inside the for-each) so it's easier to maintain (and re-use).

    Once you get this working you'll be able to start tweaking. If you already have the complete HTML for a Project it should be quite easy to start picking the dynamic parts from within the template.

    Hope this helps ...

    /Chriztian

  • Patrick 23 posts 83 karma points
    Mar 16, 2012 @ 21:19
    Patrick
    0

    It helps, but I'm not there yet.

    What's still a problem is the following.
    Item is a child of Portfolio, a child has an image with the alias display.
    It seemed logic to me to loop through alle Items like coded below.
    Regard my point of origin from where xslt is running is the node above Portfolio.

    I hope I've epxlained it a bit more like this.
    Please any help on what I'm doing wrong

    <xsl:for-each select="$currentPage/ancestor-or-self::root//Portfolio/Item">
            <li>
              <xsl:variable name="media" select="umbraco.library:GetMedia(display, 'false')" />
            </li>
      </xsl:for-each>

Please Sign in or register to post replies

Write your reply to:

Draft