I have a property in my doctype that allows the editors to select an image for each page in the tree if they so choose. If they don't want to select an image, I'm attempting to show the parent image for the node. I've just started scratching the surface of XSLT and can't quite figure out how to do it.
Here's what I've come up with that works fine if there is a PageImage set for the current node. The second <when> test is where I'm trying to pull in the parent PageImage if one doesn't exist for the current node.
If anyone can point out what I'm doing wrong I'd appreciate it.
Code:
<xsl:choose>
<xsl:when test="string($currentPage/data [@alias='PageImage']) != '' ">
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias='PageImage'], 'false')/data [@alias = 'umbracoFile']"/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="$currentPage/data [@alias = 'DisplayName']"/></xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="string(../data [@alias='PageImage']) != '' ">
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="umbraco.library:GetMedia(../data [@alias='PageImage'], 'false')/data [@alias = 'umbracoFile']"/></xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="../data [@alias = 'DisplayName']"/></xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:otherwise>
No Image <br/>
<!--
<xsl:variable name="myVarName" select="ancestor-or-self::node [@alias='PageImage' != '']/@nodeName"/>
<xsl:variable name="myVarName" select="ancestor-or-self::node [@nodeTypeAlias != 'wwContentPage']/@nodeName"/>
-->
<xsl:variable name="myVarName" select="ancestor-or-self::node [@nodeTypeAlias != 'wwContentPage']/data [@alias = 'PageImage']"/>
<xsl:value-of select="$myVarName"/>
<xsl:value-of select="string(../data [@alias='PageImage']) "/>
</xsl:otherwise>
</xsl:choose>
I'm not getting an error, but the second <when> isn't returning true. I'm also not getting any data in the <xsl:otherwise> test output. I know the parent node does have the PageImage property available and filled in. I'm a total XSLT newb so don't laugh too much.
To see the output, here's a page with the PageImage filled in:
http://abcinc.devextreme.com/our-services.aspxAnd a sub page of that node that has a blank PageImage:
http://abcinc.devextreme.com/our-services/premium-financing.aspxThanks for any ideas!
Chris