I have an Umbraco 4.7 website and I have created the following XSLT to list out some "featured" nodes, I am selecting the "featured" nodes using "uComponents:Xpath checkbox list" which only allows you to select published nodes. This is all works great apart from when a user unpublishes or deletes one the nodes that has been selected as "featured" which causes my XSLT to throw an error. I assume I need to add in some type of IF statement or something into the for:each that checks for only published nodes but I do not know how to do this. Can someone please help? My XSLT so far is:
I think you should look into something like selecting the nodes where the @nodeName attribute is in fact not empty for instance
Like this <xsl:variable name="mediaId" select="number($node/homepageImage[@nodeName !=''])" />
I'm a bit unsure here since I can't remember what the XML looks like for media in 4.7 as I write this, but it's something like that you need to look into.
If you want further help on this, then please post a dump of the xml you get returned from the $mediaid variable :-)
Check whether node is published in XSLT
Hi all,
I have an Umbraco 4.7 website and I have created the following XSLT to list out some "featured" nodes, I am selecting the "featured" nodes using "uComponents:Xpath checkbox list" which only allows you to select published nodes. This is all works great apart from when a user unpublishes or deletes one the nodes that has been selected as "featured" which causes my XSLT to throw an error. I assume I need to add in some type of IF statement or something into the for:each that checks for only published nodes but I do not know how to do this. Can someone please help? My XSLT so far is:
Hi Trevor
I think you should look into something like selecting the nodes where the @nodeName attribute is in fact not empty for instance
Like this <xsl:variable name="mediaId" select="number($node/homepageImage[@nodeName !=''])" />
I'm a bit unsure here since I can't remember what the XML looks like for media in 4.7 as I write this, but it's something like that you need to look into.
If you want further help on this, then please post a dump of the xml you get returned from the $mediaid variable :-)
/Jan
Hi Jan,
Thanks for the response, from what you suggested I managed to come up with the following IF statement which appears to resolve my issue:
So my full XSLT is now:
<ul>
<xsl:for-each select="umbraco.library:GetXmlNodeById(1076)/featuredProperties/XPathCheckBoxList/nodeId">
<xsl:sort select="randomTools:GetRandom(0,count(umbraco.library:GetXmlNodeById(1076)/featuredProperties/XPathCheckBoxList/nodeId))" order="descending" />
<xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />
<xsl:variable name="mediaId" select="number($node/homepageImage)" />
<xsl:if test="$node/@nodeName !=''">
<li>
<div class="featuredProperty">
<div class="image">
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<img>
<xsl:attribute name="src">
<xsl:value-of select="$mediaNode/umbracoFile"/>
</xsl:attribute>
<xsl:attribute name="alt">
</xsl:attribute>
</img>
</xsl:if>
</div>
<div class="heading">
<xsl:variable name="bedrooms" select="$node/bedrooms" />
<xsl:variable name="propertyType" select="$node/propertyType" />
<xsl:value-of select="umbraco.library:GetXmlNodeById($bedrooms)/@nodeName"/> bedroom <xsl:value-of select="umbraco.library:GetXmlNodeById($propertyType)/@nodeName"/>
</div>
<div class="price">
£<xsl:value-of select="$node/price"/>pcm
</div>
<div class="description">
<xsl:value-of select="$node/briefDescription"/>
</div>
<div class="line">
<xsl:comment><!-- --></xsl:comment>
</div>
<div class="link">
<a href="{umbraco.library:NiceUrl($node/@id)}">find out more</a>
</div>
</div>
</li>
</xsl:if>
</xsl:for-each >
</ul>
is working on a reply...