Copied to clipboard

Flag this post as spam?

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


  • Elad Lachmi 112 posts 144 karma points
    Mar 21, 2011 @ 05:46
    Elad Lachmi
    0

    XSLT sometimes works, sometimes gives error

    I have the following XSLT:

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

    <!-- start writing XSLT -->
      <xsl:for-each select="$currentPage//broker [@isDoc]">
        <div class="small-box">
          <xsl:if test="position() mod 3 = 0">
            <xsl:attribute name="class">nomar2</xsl:attribute>
          </xsl:if>
          <div class="small-top">
            <div class="small-bottom">
              <div class="box-logo">
                <img src="{umbraco.library:GetMedia(./brokerLogo,0)/umbracoFile}" width="123" height="49" alt="" />
              </div>
              <h2><xsl:value-of select="./brokerName" /></h2>
              <p><xsl:value-of select="./shortDescription" /></p>
            </div>
          </div>
        </div>
      </xsl:for-each>
    </xsl:template>

    </xsl:stylesheet>

     

    Sometimes it works and sometimes it shows an error:

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

    When I remove the GetMedia tag, it is able to save the file.

    Any ideas? I`m going a little nuts here.

    Thank you.

  • Elad Lachmi 112 posts 144 karma points
    Mar 21, 2011 @ 06:49
    Elad Lachmi
    0

    Well I found the problem.

    The xslt breaks when the brokerLogo property doesn't have a media ID associated with it.

    I'm guessing ./brokerLogo return either null or some empty string and GetMedia fails.

    If this was c++ for instance, I would just check that ./brokerLogo is not null.

    How can I do this in XSLT? 

    I want to present a generic logo if the client does not submit their logo.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 21, 2011 @ 07:52
    Jan Skovgaard
    1

    Hi Elad

    You would make a check to make sure that the property has a value. Try having a look at the example on how to use the GetMedia extension here: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

    /Jan

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 21, 2011 @ 08:39
    Kim Andersen
    0

    Hi Elad

    I think you should have a look at the Wiki Jan links to, but if you just wan to expand the code that you've already got, you can add a small check like this:

    <xsl:if test="./brokerLogo != ''">
    <
    div class="box-logo">
          <img src="{umbraco.library:GetMedia(./brokerLogo,0)/umbracoFile}" width="123" height="49" alt="" />
    </div>
    </xsl:if>

    /Kim A

  • Elad Lachmi 112 posts 144 karma points
    Mar 21, 2011 @ 08:51
    Elad Lachmi
    0

    Usually I look for good coding practices, today I`m just looking for a quick fix :). Thank you both!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

    Continue discussion

Please Sign in or register to post replies