Copied to clipboard

Flag this post as spam?

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


  • Steve Barnhouse 40 posts 63 karma points
    Aug 05, 2010 @ 21:48
    Steve Barnhouse
    0

    xslt change for Umbraco 4.5.1 to display images

    The newsImage.xslt (and similar code in newsList.xslt) files need a minor change to correctly display images under Umbraco 4.5.1.

    Change from this:

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/newsImage, false() )/Image/umbracoFile" />

    to this:

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/newsImage, false() )/umbracoFile" /> 


  • Carlo Cabrales 58 posts 77 karma points
    Aug 10, 2010 @ 19:27
    Carlo Cabrales
    0

    I've made the appropriate code changes to newsimage.xslt which worked.. 

     

    but now i get this error when I click on the news section

    "Error parsing XSLT file: \xslt\newsList.xslt"

     

    I am running umbraco 4.5.1 and the latest downloadable package from the umbraco package repository

  • Kim Andersen 1447 posts 2197 karma points MVP
    Aug 10, 2010 @ 19:37
    Kim Andersen
    0

    Hi Carlo

    Could you provide us with the XSLT from your newsList.xslt-file? I think that will help some of us solve your problem.

    /Kim A

  • Carlo Cabrales 58 posts 77 karma points
    Aug 10, 2010 @ 19:41
    Carlo Cabrales
    0

    Also, when i attempt to save i get this error.. "Error occured

    System.OverflowException: Value was either too large or too small for an Int32. "

    For now, i worked around it by commenting out the news_image div

    <?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"
      exclude-result-prefixes="msxml umbraco.library">


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

     

    <xsl:param name="currentPage"/>


    <xsl:template match="/">
     
      
      <xsl:variable name="datenow" select="umbraco.library:CurrentDate()" /> 
      <xsl:variable name="featuredArticle">
        <xsl:choose>
          <xsl:when test="string($currentPage/newsFeaturedArticle) != ''">
            <xsl:value-of select="$currentPage/newsFeaturedArticle" />
          </xsl:when>
          <xsl:otherwise>
            <!-- should support autofolders if we use // -->
            <xsl:for-each select="$currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and name()='NewsItem']">
              <xsl:sort select="current()/newsDate"  order="descending" />
              <xsl:if test="position() = 1">
                <xsl:value-of select="current()/@id" />
              </xsl:if>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      
      
      
      <xsl:variable name="recordsPerPage">
        <xsl:choose>
          <xsl:when test="string($currentPage/newsPerPage) != ''">
            <xsl:value-of select="$currentPage/newsPerPage" />
          </xsl:when>
          <xsl:otherwise>15</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="pageNumber" >
        <xsl:choose>
          <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      
      <xsl:variable name="numberOfRecords" select="count($currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and name()='NewsItem' and @id != $featuredArticle])"/>
      <ul class="news_list">
        
        <xsl:call-template name="featuredNewsItem">
          <xsl:with-param name="selectedItem" select="$featuredArticle" />
        </xsl:call-template>
        
        <xsl:for-each select="$currentPage//* [@isDoc and string(./umbracoNaviHide) != '1' and name()='NewsItem' and @id != $featuredArticle]">
          <xsl:sort select="current()/newsDate"  order="descending" />
          <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber) and position() &lt;= number($recordsPerPage * number($pageNumber) + $recordsPerPage )">
            <li>
              <xsl:if test="string(current()/newsImage) != ''">
                <div class="news_image">
                  <title="{current()/@nodeName}" href="{umbraco.library:NiceUrl(current()/@id)}">  
                    <img>
                      <xsl:attribute name="src"-->
                        <!-- <xsl:value-of select="umbraco.library:GetMedia(current()/newsImage, false() )/Image/umbracoFile" /> -->
                        <xsl:value-of select="umbraco.library:GetMedia($currentPage/newsImage, false() )/umbracoFile" />
                        
                        </xsl:attribute>
                      <xsl:attribute name="alt">
                         <xsl:value-of select="current()/@nodeName"/>
                      </xsl:attribute>
                    </img>
                  </a>
                </div>
              </xsl:if>
              <div class="news_content">
                <h3>
                  <title="{current()/@nodeName}" href="{umbraco.library:NiceUrl(current()/@id)}">
                    <xsl:value-of select="current()/pageHeading"/>
                  </a>
                </h3>
                <class="news_date"><xsl:value-of select="umbraco.library:FormatDateTime(./newsDate, 'd MMMM, yyyy')"/></p>
                <p><xsl:value-of select="umbraco.library:ReplaceLineBreaks(./newsSummary)" disable-output-escaping="yes" />&#8230;</p>
                <p><title="{current()/@nodeName}" href="{umbraco.library:NiceUrl(current()/@id)}">Read full story »</a></p>
              </div>
            </li>
          </xsl:if>
        </xsl:for-each>
        
      </ul>
      <class="paging">
        <xsl:if test="$pageNumber &gt; 0">
          <href="?page={$pageNumber -1}">previous</a>  
        </xsl:if>
        
        <!--<xsl:call-template name="for.loop">
          <xsl:with-param name="i">1</xsl:with-param>
          <xsl:with-param name="page" select="$pageNumber +1"></xsl:with-param>
          <xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>
        </xsl:call-template>-->
        
        <xsl:if test="(($pageNumber +1 ) * $recordsPerPage) &lt; ($numberOfRecords)">
          <xsl:text>&#160;&#160;&#160;</xsl:text><href="?page={$pageNumber +1}">next</a>
        </xsl:if>
      &#160;</p>
    </xsl:template>

     

    <xsl:template name="for.loop">
      <xsl:param name="i"/>
      <xsl:param name="count"/>
      <xsl:param name="page"/>
      
      <xsl:if test="$i &lt;= $count">
        <xsl:if test="$page != $i">
          <href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}" >
            <xsl:value-of select="$i" />
          </a>
          
        </xsl:if>
        <xsl:if test="$page = $i">
          <xsl:value-of select="$i" />
        </xsl:if>
      </xsl:if>

      <xsl:if test="$i &lt;= $count">
        <xsl:call-template name="for.loop">
          <xsl:with-param name="i">
            <xsl:value-of select="$i + 1"/>
          </xsl:with-param>
          <xsl:with-param name="count">
            <xsl:value-of select="$count"/>
          </xsl:with-param>
          <xsl:with-param name="page">
            <xsl:value-of select="$page"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:if>

    </xsl:template>

    <xsl:template name="featuredNewsItem">
      
      <xsl:param name="selectedItem" />
      <xsl:variable name="featuredItem" select="umbraco.library:GetXmlNodeById($selectedItem)" />
            
      <li class="featured_news">
        <xsl:if test="string($featuredItem/newsImage) != ''">
          <div class="main_news_image">
            <title="{$featuredItem/@nodeName}" href="{umbraco.library:NiceUrl($featuredItem/@id)}">  
              <img>
                <xsl:attribute name="src">
                  <!--<xsl:text>/umbraco/ImageGen.ashx?image=</xsl:text>-->
                  <xsl:value-of select="umbraco.library:GetMedia($featuredItem/newsImage, false() )/Image/umbracoFile" />
                  <!-- <xsl:value-of select="umbraco.library:GetMedia($currentPage/newsImage, false() )/umbracoFile" /> -->
                  
                  <!--<xsl:text>&amp;width=305&amp;compression=100</xsl:text>-->
                </xsl:attribute>
                <xsl:attribute name="alt">
                   <xsl:value-of select="$featuredItem/newsDate"/>
                </xsl:attribute>
              </img>
            </a>
          </div>
        </xsl:if>
        <div class="main_news_item">
          <h3>
            <title="{$featuredItem/@nodeName}" href="{umbraco.library:NiceUrl($featuredItem/@id)}">
              <xsl:value-of select="$featuredItem/pageHeading"/>
            </a>
          </h3>
          <class="news_date"><xsl:value-of select="umbraco.library:FormatDateTime($featuredItem/newsDate, 'd MMMM, yyyy')"/></p>
          <p><xsl:value-of select="umbraco.library:ReplaceLineBreaks($featuredItem/newsSummary)" disable-output-escaping="yes" />...</p>
          <p><title="{$featuredItem/@nodeName}" href="{umbraco.library:NiceUrl($featuredItem/@id)}">Read full story »</a></p>
        </div>
      </li>
      
    </xsl:template>


    </xsl:stylesheet>

  • Kim Andersen 1447 posts 2197 karma points MVP
    Aug 10, 2010 @ 19:46
    Kim Andersen
    0

    Carlo, can you try changing this line:

    <xsl:value-of select="umbraco.library:GetMedia($currentPage/newsImage, false() )/umbracoFile" />

    to this:

    <xsl:value-of select="umbraco.library:GetMedia(./newsImage, 'false')/umbracoFile" />

    /Kim A

  • Carlo Cabrales 58 posts 77 karma points
    Aug 10, 2010 @ 20:46
    Carlo Cabrales
    0

    I still recieved this error

    Error reading XSLT file: \xslt\newsList.xslt

  • Carlo Cabrales 58 posts 77 karma points
    Aug 10, 2010 @ 20:47
    Carlo Cabrales
    0

    scratch that, it worked! THANK YOU!

  • Steve Barnhouse 40 posts 63 karma points
    Aug 10, 2010 @ 20:52
    Steve Barnhouse
    0

    Carlo,

    I noticed that if there are no published news items, then newsList.xslt generates an error.

    As a workaround, make sure there is a published News Item.  In the Content section, under the News node, create a new News Item if there are none, then select Save and publish.

    --steve

  • Carlo Cabrales 58 posts 77 karma points
    Aug 16, 2010 @ 14:46
    Carlo Cabrales
    0

    I noticed that an image on the first new item brings up an <img> tag that isn't associated with a "src" thus looking as if it can't find an image. any clues?

  • MartinB 411 posts 512 karma points
    Aug 16, 2010 @ 14:58
    MartinB
    0

    Could that be due to a missing uploaded file for the first image node?

    Is there an image associated with the node in the media section?

  • Carlo Cabrales 58 posts 77 karma points
    Aug 16, 2010 @ 14:59
    Carlo Cabrales
    0

    yes there is a associated image in the media section

Please Sign in or register to post replies

Write your reply to:

Draft