简体   繁体   English

umbraco xslt getMedia错误

[英]umbraco xslt getMedia error

Searching for an error with GetMedia on Forum, I read that the variable i give the functions is not an integer. 在论坛上使用GetMedia搜索错误时,我读到我赋予函数的变量不是整数。

Here is the error: System.OverflowException: Value was either too large or too small for an Int32. 这是错误:System.OverflowException:对于Int32,值太大或太小。

I check my variable: 我检查我的变量:

<xsl:value-of select="$currentPage/image" />

The output was: 输出为:

1663

then i try this: 然后我试试这个:

<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/image, false())" />

It returns me the error I wrote you above. 返回我上面写给你的错误。 If i wrote 1663 instead of $currentPage/image it works but then it's hardcoded and it musn't be hardcoded. 如果我写的是1663而不是$ currentPage / image,那么它可以工作,但是它是硬编码的,所以它不是硬编码的。

Here my xslt 这是我的xslt

<xsl:template match="/">

<!-- start writing XSLT -->
<xsl:value-of select="$currentPage/image" />
<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/image, false())" />
<div class="tfirst">
<p>
    <!--xsl:if test="not($media/error)">
        <img src="{$media/umbracoFile}" class="left timg" />
    </xsl:if-->
    <div class="ttext">
        <h2><xsl:value-of select="umbraco.library:StripHtml($currentPage/title)" /></h2>
        <xsl:value-of select="$currentPage/abstractText" disable-output-escaping="yes" />
    </div>
</p>
</div>
<div class="ttext">
<xsl:if test="$currentPage/showMultipleColumns='1'">
    <xsl:attribute name="class">showMultipleColumns</xsl:attribute>
</xsl:if>
<xsl:value-of select="$currentPage/bodyText" disable-output-escaping="yes" />
</div>

</xsl:template>

Thank you for your help. 谢谢您的帮助。 Benjamin 本杰明

Edit------------------ 编辑 - - - - - - - - -

I've tried to add a if test but now it give me another error if i replace $currentPage/image by 1663 : System.Xml.Xsl.XslTransformException: To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function. 我试图添加一个if测试,但是如果我将$ currentPage / image替换为1663,它现在会给我另一个错误:System.Xml.Xsl.XslTransformException:要在路径表达式中使用结果树片段,请先将其转换为使用msxsl:node-set()函数进行节点设置。

If i let the $currentPage/image I always have: System.OverflowException: Value was either too large or too small for an Int32. 如果我让$ currentPage / image我始终拥有:System.OverflowException:对于Int32,值太大或太小。

Here is the xslt: 这是xslt:

<xsl:variable name="atest" select="umbraco.library:GetMedia($currentPage/image, false())" />
<xsl:variable name="media">
    <xsl:if test="$currentPage/image &gt; 0">
        <xsl:value-of select="$atest" />
    </xsl:if>
</xsl:variable>

Edit2------------ 编辑2 ------------

Trying this below always getting the error: System.OverflowException: Value was either too large or too small for an Int32. 在下面尝试此操作总是会收到错误:System.OverflowException:对于Int32,值太大或太小。

<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/image, false())" />
<xsl:if test="$media">
  <img src="{$media/umbracoFile}" class="left timg" />
</xsl:if>

You need to check if your $currentPage/image is > 0 before you call the umbraco.Library:GetMedia() function. 在调用umbraco.Library:GetMedia()函数之前,需要检查$ currentPage / image是否大于0。 I can't remember why it was like that, but I've encountered the same issue a few years ago and if I recall it correctly, there was a reason for doing so. 我不记得为什么会这样,但是几年前我也遇到过同样的问题,如果我没记错的话,这样做是有原因的。

try this: 尝试这个:

<xsl:variable name="mediaId" select="$currentPage/image)" />    
<xsl:if test="$mediaId > 0">
   <xsl:variable name="media" select="umbraco.library:GetMedia($mediaId, 0)" />
</xsl:if>

EDIT: 编辑:

I'm confused with the check you need to add in the Umbraco Macro Editor with this. 我对您需要为此添加到Umbraco宏编辑器中的检查感到困惑。 Rendering an image should be as simple as this: 渲染图像应该像这样简单:

<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/image, 0)" />

 <xsl:if test="$media">
        <xsl:variable name="url" select="$media/umbracoFile" />
        <xsl:variable name="width" select="$media/umbracoWidth" />
        <xsl:variable name="height" select="$media/umbracoHeight" />
        <img src="{$url}" width="{$width}" height="{$height}" />
 </xsl:if>

Thanks for your help. 谢谢你的帮助。 Found my problem solution. 找到了我的问题解决方案。 Because my image is not mandatory (yes something that i should tell before). 因为我的图片不是强制性的(是的,我之前应该告诉别人)。 I just did that: 我只是这样做了:

<xsl:if test="$currentPage/image &gt; 0">
  <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/image, false())" />
  <xsl:if test="not($media/error)">
    <img src="{$media/umbracoFile}" class="left timg" />
  </xsl:if>
</xsl:if>

Now it just works fine. 现在一切正常。 Thank you for your help. 谢谢您的帮助。 Have a great day. 祝你有美好的一天。 Benjamin 本杰明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM