Copied to clipboard

Flag this post as spam?

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


  • Geoff Stokes 19 posts 38 karma points
    Aug 19, 2011 @ 08:03
    Geoff Stokes
    0

    Looping and page selection in XSLT problem

    Hi All,

    I have the following XSLT code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:for-each select="$currentPage/ancestor-or-self::* [name()='Event' and umbraco.library:DateGreaterThanOrEqualToday(./eventDate)]">
    <div class="event_1_main">
      <div class="event_img"><img src="/images/event_img_2.jpg" alt="" /></div>
        <div class="event_right_part">
           <h2 class="event_title"><xsl:value-of select="current()/@nodeName"/></h2>
            <div class="event_text">
            <strong><xsl:value-of select="current()/eventDate"/></strong><br />
              <xsl:value-of select="current()/eventDescription"/>
            </div>
          <div class="viewmore_btn"><href="{umbraco.library:NiceUrl(current()/@id)}">VIEW MORE</a></div>
        </div>
    </div>
    </xsl:for-each>

    </xsl:template>

    </xsl:stylesheet>

    and it displays nothing on my page. What is the correct way to select child elements of the current page by type?

    I will also need to perform a similar selection in another piece of code, so how does one select elements from under a specific node?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Aug 19, 2011 @ 09:02
    Chriztian Steinmeier
    0

    Hi Geoff,

    Try this slight refactoring for a simple way to illustrate this:

    <xsl:template match="/">
    
        <xsl:apply-templates select="$currentPage/ancestor-or-self::Event[umbraco.library:DateGreaterThanOrEqualToday(eventDate)]" />
    
    </xsl:template>
    
    <!-- Template for an Event node -->
    <xsl:template match="Event">
        <div class="event_1_main">
            <div class="event_img">
                <img src="/images/event_img_2.jpg" alt="" />
            </div>
                <div class="event_right_part">
                    <h2 class="event_title">
                        <xsl:value-of select="@nodeName"/>
                    </h2>
                    <div class="event_text">
                        <strong>
                            <xsl:value-of select="eventDate"/>
                        </strong>
                        <br />
                        <xsl:value-of select="eventDescription"/>
                    </div>
                <div class="viewmore_btn">
                    <a href="{umbraco.library:NiceUrl(@id)}">VIEW MORE</a>
                </div>
            </div>
        </div>
    </xsl:template>
    

    Note that once you're inside a template (or a for-each for that matter) you can just refer to child elements without any prefix (current() or ./ etc.) at all.

    /Chriztian

  • Geoff Stokes 19 posts 38 karma points
    Aug 19, 2011 @ 09:39
    Geoff Stokes
    0

    Alright, thanks for your help.

    I'm having trouble getting an image to display in this loop.

    <img src="{umbraco.library:GetMedia(current()/eventImage, true())}" alt="" />

    Gives me "/media/15926/banner.jpg67326887970jpg" - "67326887970jpg" should not be there. What am I doing wrong?

    Thanks.

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 19, 2011 @ 10:43
    Fuji Kusaka
    0

    Hi Geoff,

    Seems like you are picking the image from the media secion. You could try this chaging this

    <imgsrc="{umbraco.library:GetMedia(current()/eventImage, true())}"alt=""/>

    to

    <img src="{umbraco.library:GetMedia(eventImage, 'true')/umbracoFile}" alt=""/>

     

    //fuji

Please Sign in or register to post replies

Write your reply to:

Draft