Copied to clipboard

Flag this post as spam?

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


  • Probocop 51 posts 71 karma points
    Jul 14, 2010 @ 15:58
    Probocop
    0

    Retrieving a nodes pageImage when listing

    I've got a news page on my site, which lists all the subpages (news articles) in a macro.

    Each of the subpages has an image (alias pageImage)

    I've got the following XSLT code, but It's not working:

    <?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="/">

    <!-- The fun starts here -->
    <ul id="reports">
    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <xsl:sort select="@createDate" order="descending" />
       
    <li>
           
    <img>
               
    <xsl:attribute name="src">
                   
    <xsl:text>/umbraco/ImageGen.ashx?image=</xsl:text>
                   
    <xsl:value-of select="umbraco.library:GetMedia(data[@alias='pageImage'],'true')/data[@alias='umbracoFile']"/>
                   
    <xsl:text>&amp;width=125&amp;height=125&amp;constrain=true&amp;pad=true&amp;BgColor=white&amp;transparent=false</xsl:text>
               
    </xsl:attribute>
               
    <xsl:attribute name="alt">
                   
    <xsl:value-of select="something"/>
               
    </xsl:attribute>
           
    </img>
           
    <h2><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></h2>
           
    <p class="date"><xsl:value-of select="data [@alias = 'date']" disable-output-escaping="yes"/></p>
           
    <p>Mauris sit amet augue ut felis blandit placerat. Sed tempus gravida libero. Donec placerat lacus
            eget neque. Mauris sit amet augue ut felis blandit placerat. Sed tempus gravida libero.
    </p>
           
    <p><a><img src="images/pdf.gif" alt="Download/view PDF" align="left" /> Download/View PDF</a> - 82kb</p>
       
    </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    </xsl:stylesheet>

    And the error it is giving me is:

    Error occured

    System.OverflowException: Value was either too large or too small for an Int32.
    at
    System.Convert.ToInt32(Double value)
    at
    System.Double.System.IConvertible.ToInt32(IFormatProvider provider)
    at
    System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
    at
    System.Xml.Xsl.Runtime.XmlQueryRuntime.ChangeTypeXsltArgument(XmlQueryType xmlType, Object value, Type destinationType)
    at
    System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args)
    at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
    at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, TextWriter results)
    at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\presentation\umbraco\webservices\codeEditorSave.asmx.cs:line 124

    Anybody have any idea what's going wrong? I know it's something to do with the <xsl:value-of select="umbraco.library:GetMedia(data[@alias='pageImage'],'true')/data[@alias='umbracoFile']"/> line as if I hardcode an image URL, it works fine.

    Thanks!

  • Folkert 82 posts 212 karma points
    Jul 14, 2010 @ 16:40
    Folkert
    0

    Try to check if the pageImage contains a value first.

    use xsl:choose for getting the value, use default value if there is no image value.

  • Probocop 51 posts 71 karma points
    Jul 14, 2010 @ 17:04
    Probocop
    0

    Would you do the <xsl:choose> within the <xsl:attribute="src">?

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jul 14, 2010 @ 17:15
    Matt Brailsford
    0

    I'd probably just do something along the lines of

    <xsl:if test="string-length(data[@alias='pageImage']) &gt; 0">
    <img>           
     <xsl:attribute name="src">               
      <xsl:text>/umbraco/ImageGen.ashx?image=</xsl:text>              
      <xsl:value-of select="umbraco.library:GetMedia(data[@alias='pageImage'],'true')/data[@alias='umbracoFile']"/>
      <xsl:text>&amp;width=125&amp;height=125&amp;constrain=true&amp;pad=true&amp;BgColor=white&amp;transparent=false</xsl:text>           
     </xsl:attribute>           
     <xsl:attribute name="alt">               
      <xsl:value-of select="something"/>           
     </xsl:attribute>       
    </img>
    </xsl:if>

    This just checks to see if the 'pageImage' has a value, and if it does, displays the image, if not, no image is displayed.

    Matt

  • Folkert 82 posts 212 karma points
    Jul 14, 2010 @ 17:29
    Folkert
    0

    I'd prefer the xsl:choose for having a fall-back image.

    Use xsl:choose for testing if there is a value. If there is one, set the value, otherwise use a default value. So you allways will have a image, and the layout will not be broken.
    Create a xsl:variable within the img tag so the img attribute can be set dynamically.

    [pseudocode]
    <img>
    <xsl:variable name="imageSource" ...
    <xsl:choose ...etc...
    </xsl:variable>

    <xsl:attribute name="src" value="$imageSource"/>

    </img>

  • Probocop 51 posts 71 karma points
    Jul 14, 2010 @ 17:29
    Probocop
    0

    Ah that's solved my problem! It was only breaking if a node didn't have an image, so doing that check has gotten rid of the errors. Thank you very much!

     

    And yes, I will be doing an xsl:choose rather than xsl:if so I can put the fallback image in the xsl:otherwise

  • Folkert 82 posts 212 karma points
    Jul 14, 2010 @ 17:33
    Folkert
    0

    Fot those scenarios, I allways create a 'default' directory in my media section. In this folder I upload default images for all kind of doc types in my project.

Please Sign in or register to post replies

Write your reply to:

Draft