Get Parent node property Options
bnkrazy
Posted: Thursday, July 17, 2008 6:26:59 AM
Rank: Enthusiast

Joined: 5/13/2008
Posts: 37
Location: VA, USA
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. Angel

To see the output, here's a page with the PageImage filled in:
http://abcinc.devextreme.com/our-services.aspx
And a sub page of that node that has a blank PageImage:
http://abcinc.devextreme.com/our-services/premium-financing.aspx

Thanks for any ideas!

Chris
Petr Snobelt
Posted: Thursday, July 17, 2008 8:33:33 AM
Rank: Aficionado

Joined: 10/2/2007
Posts: 149
Location: Czech Republic
Try use recursion, it's elegant method for solving your problem
http://forum.umbraco.org/yaf_postst2751_XSLT-Tip--Display-a-field-recursively.aspx
bnkrazy
Posted: Thursday, July 17, 2008 3:06:17 PM
Rank: Enthusiast

Joined: 5/13/2008
Posts: 37
Location: VA, USA
Brilliant! That's exactly what I needed. Applause

Thanks!

Chris
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.