Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Sep 15, 2011 @ 13:22
    Anthony Candaele
    0

    problem with xslt

    Hi,

    I have this xslt script that orders conference items under the headings 'upcoming conferences' and 'past conferences'.

    But the result is not exactly what I hoped for because the headings are repeated for every conference item.

    This is the script:

    <xsl:for-each select="$currentPage/* [(name() = $documentTypeAlias and string(umbracoNaviHide) != '1') and umbraco.library:DateGreaterThanOrEqualToday(conferenceStartDate)]">
            <name="upcoming">&nbsp;</a>
            <h2>Upcoming conferences</h2>
            <h3><xsl:value-of select="conferenceTitle"/></h3>
            <xsl:if test="string-length(conferenceImage) &gt; 0">
            <img src="{umbraco.library:GetMedia(conferenceImage, false())/umbracoFile}" alt="{lectureTitle}" />
            </xsl:if>
            <class="theme"><xsl:value-of select="conferenceTheme"/></p>
            <p>
            <xsl:choose>
              <xsl:when test="conferenceEndDate != ''">
                <xsl:if test="conferenceStartDate != ''">
                  <strong>Date:</strong>&nbsp;from <xsl:value-of select="umbraco.library:FormatDateTime(conferenceStartDate, 'dd/MM/yyyy')"/>
                  to <xsl:value-of select="umbraco.library:FormatDateTime(conferenceEndDate, 'dd/MM/yyyy')"/>
                </xsl:if>
              </xsl:when>
              <xsl:otherwise>
                <xsl:if test="conferenceStartDate != ''">
                  <strong>Date:</strong>&nbsp;<xsl:value-of select="umbraco.library:FormatDateTime(conferenceStartDate, 'dd/MM/yyyy')"/>
                </xsl:if>
              </xsl:otherwise>
            </xsl:choose>
            </p>  
            </xsl:for-each>
    <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1' and not(umbraco.library:DateGreaterThanOrEqualToday(conferenceStartDate))]">
          <name="past">&nbsp;</a>
          <h2>Past conferences</h2>
          <h3><xsl:value-of select="conferenceTitle"/></h3>
          <xsl:if test="string-length(conferenceImage) &gt; 0">
          <img src="{umbraco.library:GetMedia(conferenceImage, false())/umbracoFile}" alt="{lectureTitle}" />
          </xsl:if>
          <class="theme"><xsl:value-of select="conferenceTheme"/></p>
          <p>
          <xsl:choose>
              <xsl:when test="conferenceEndDate != ''">
                <xsl:if test="conferenceStartDate != ''">
                  <strong>Date:</strong>&nbsp;from <xsl:value-of select="umbraco.library:FormatDateTime(conferenceStartDate, 'dd/MM/yyyy')"/>
                  to <xsl:value-of select="umbraco.library:FormatDateTime(conferenceEndDate, 'dd/MM/yyyy')"/>
                </xsl:if>
              </xsl:when>
              <xsl:otherwise>
                <xsl:if test="conferenceStartDate != ''">
                  <strong>Date:</strong>&nbsp;<xsl:value-of select="umbraco.library:FormatDateTime(conferenceStartDate, 'dd/MM/yyyy')"/>
                </xsl:if>
              </xsl:otherwise>
            </xsl:choose>     
          <xsl:if test="string-length(conferenceLocation) &gt; 0">
          <xsl:value-of select="conferenceLocation"/>
          </xsl:if>
          </p>      
          <p><xsl:value-of select="conferenceSummary"/></p>
          <p><href="{umbraco.library:NiceUrl(@id)}" class="tekst">More information</a></p>
    </xsl:for-each>

    I guess I can solve this by creating an xslt-template for upcoming conferences and another xslt-template for past conferences. But I don't know how to do this.

    Can someone help me? 

    Thanks,

    Anthony Candaele

  • Sean Holmesby 61 posts 82 karma points
    Sep 19, 2011 @ 04:02
    Sean Holmesby
    1

    Firstly, your for loops are slightly different....the second one missing a location and summary, so if you want them pretty much the same, then you should use a template. Even so, if you want it different, you could put it all in a template, then put an <xsl:if around the specific parts.

    Here is what I've come up with. This is untested, so see how you go.

    <xsl:template match="*">
            <h2>Upcoming conferences</h2>
            <xsl:apply-templates mode="conference-item" select="$currentPage/* [(name() = $documentTypeAlias and string(umbracoNaviHide) != '1') and umbraco.library:DateGreaterThanOrEqualToday(conferenceStartDate)]">
                <xsl:with-param name="conference-type" select="'upcoming'" />
            </xsl:apply-templates>
    
            <h2>Past conferences</h2>
            <xsl:apply-templates mode="conference-item" select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1' and not(umbraco.library:DateGreaterThanOrEqualToday(conferenceStartDate))]">
                <xsl:with-param name="conference-type" select="'past'" />
            </xsl:apply-templates>
        </xsl:template>
    
    
        <!-- Template for each conference item -->
        <xsl:template mode="conference-item" match="*">
            <xsl:param name="conference-type" />
    
            <a name="{$conference-type}">&nbsp;</a>
            <h3>
                <xsl:value-of select="conferenceTitle"/>
            </h3>
    
            <xsl:if test="string-length(conferenceImage) &gt; 0">
                <img src="{umbraco.library:GetMedia(conferenceImage, false())/umbracoFile}" alt="{lectureTitle}" />
            </xsl:if>
            <p class="theme">
                <xsl:value-of select="conferenceTheme"/>
            </p>
    
            <p>
                <xsl:choose>
                    <xsl:when test="conferenceEndDate != ''">
                        <xsl:if test="conferenceStartDate != ''">
                            <strong>Date:</strong>&nbsp;from <xsl:value-of select="umbraco.library:FormatDateTime(conferenceStartDate, 'dd/MM/yyyy')"/>
                            to <xsl:value-of select="umbraco.library:FormatDateTime(conferenceEndDate, 'dd/MM/yyyy')"/>
                        </xsl:if>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:if test="conferenceStartDate != ''">
                            <strong>Date:</strong>&nbsp;<xsl:value-of select="umbraco.library:FormatDateTime(conferenceStartDate, 'dd/MM/yyyy')"/>
                        </xsl:if>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:if test="string-length(conferenceLocation) &gt; 0">
                    - <xsl:value-of select="conferenceLocation"/>
                </xsl:if>
            </p>
    
            <p>
                <xsl:value-of select="conferenceSummary"/>
            </p>
            <p>
                <a href="{umbraco.library:NiceUrl(@id)}" class="tekst">More information</a>
            </p>
        </xsl:template>

     

  • Anthony Candaele 1197 posts 2049 karma points
    Sep 19, 2011 @ 10:55
    Anthony Candaele
    0

    Hi Sean,

    Thanks a lot, I solved my problem by creating two two xslt-files, one looping through the upcoming conference nodes and one looping through the past conference nodes. Then on my template I implemented two macro's. 

    But you solution is so much more elegant. I learnt a great new thing about Xslt and using the <apply-templates mode="...."> element.

    Thanks a lot, you rock!

    Anthony Candaele

  • Sean Holmesby 61 posts 82 karma points
    Sep 19, 2011 @ 14:49
    Sean Holmesby
    0

    No worries Anthony. Glad I could help.

Please Sign in or register to post replies

Write your reply to:

Draft