Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have the following XSLT:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]><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.
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.
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
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
Usually I look for good coding practices, today I`m just looking for a quick fix :). Thank you both!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
XSLT sometimes works, sometimes gives error
I have the following XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<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.
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.
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
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:
/Kim A
Usually I look for good coding practices, today I`m just looking for a quick fix :). Thank you both!
is working on a reply...