2012-04-04 46 views
0

我的目的是創建一個新聞列表,並且會附加一個縮略圖(news_teaserimage)給一些新聞。問題是,如果我只在某些節點中選擇媒體,我會得到一個xslt錯誤,並且不會生成任何代碼。如果我在所有節點中選擇媒體,那麼它的工作原理是:無論有沒有圖像,代碼都會生成節點。如果沒有選擇圖像,則不會顯示。Umbraco - 顯示不是所有媒體都被選中時的節點

我在做什麼錯?

<ul> 

<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']"> 
<xsl:variable name="media" select="umbraco.library:GetMedia(news_teaserimage, 0)"/> 

    <li> 
    <h2><xsl:value-of select="@nodeName"/></h2> 
    <h5><xsl:value-of select="@createDate"/></h5> 

<xsl:if test="news_teaserimage"> 
<img src="{$media/umbracoFile}" width="70" height="70" style="float: left; padding-right: 10px; padding-bottom: 10px;" /> 
</xsl:if> 

     <xsl:value-of select="news_shorttext" disable-output-escaping="yes"/> 
    <xsl:if test="news_largetext"> 
     <br /> 
<a style="float: left; clear: both; margin-top: -10px;" href="{umbraco.library:NiceUrl(@id)}"> 
     Read more 
    </a> 

</xsl:if> 


    </li> 
</xsl:for-each> 
</ul> 
+0

你能包括在你的問題的確切的錯誤信息,也。是否「Int32對於Int32來說價值不是太大就是太小」。 – 2012-04-05 00:50:01

+0

將xsl:variable標籤中的「umbraco.library:GetMedia(news_teaserimage,0)」移動到xsl:if標籤中,然後將該xsl:wrap包裝在裏邊的所有其他代碼中 – 2012-07-30 21:37:46

回答

0

調用GetMedia時,有沒有在你調用它(在你的情況news_teaserimage)變量將導致XSLT錯誤,因爲沒有媒體拿到如果媒體節點尚未被選中。您只需稍微重新調整代碼即可使其工作。將您分配「媒體」變量的代碼行移動到if語句中,以檢查news_teaserimage元素是否存在。這樣只有實際存在價值時纔會被調用。

您可能還需要將if測試更改爲如下形式:string-length(news_teaserimage)> 0,因爲如果元素存在但是爲空,它可能會觸發。

0

xsl:variable標籤移動umbraco.library:GetMedia(news_teaserimage, 0)呼叫到xsl:if標籤和包裝是xsl:if周圍所有的li代碼的其餘部分:

<ul> 
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1']"> 

    <li> 
    <xsl:if test="umbraco.library:GetMedia(news_teaserimage, 0)"> 
    <h2><xsl:value-of select="@nodeName"/></h2> 
    <h5><xsl:value-of select="@createDate"/></h5> 

    <img src="{$media/umbracoFile}" width="70" height="70" style="float: left; padding-right: 10px; padding-bottom: 10px;" /> 

    <xsl:value-of select="news_shorttext" disable-output-escaping="yes"/> 

    <xsl:if test="news_largetext"> 
     <br /> 
     <a style="float: left; clear: both; margin-top: -10px;" href="{umbraco.library:NiceUrl(@id)}"> 
     Read more 
     </a> 
    </xsl:if> 
    </li> 
</xsl:for-each> 
</ul> 
相關問題