I have some xslt which shows a series of images on the page. I would like it to check if the images are defined on the current page. If not it should check the parent page to see if they are defined there. If they are, then use them, if not then go back another level...
It works to some degree, but it takes all images, both those defined on the current page, and those on the parent page. Thats not really what i want. If toppic is defined on the current page, it shouldnt look to the parent...
I used this before to use some content from the parent node if it wasn't present on the current node. It's not the most beautiful XSLT I have written, but it worked in my case :)
Check if self or ancestor is defined then use...
I have some xslt which shows a series of images on the page.
I would like it to check if the images are defined on the current page.
If not it should check the parent page to see if they are defined there.
If they are, then use them, if not then go back another level...
My xslt so far:
<xsl:if test="$currentPage/ancestor-or-self::node/data[@alias='toppic'] != ''">
<xsl:variable name="documentNodeSet" select="$currentPage/ancestor-or-self::node/data[@alias='toppic']"/>
<xsl:for-each select="$documentNodeSet/descendant::node">
<img src="{umbraco.library:GetMedia(current(), 'false')/data [@alias='umbracoFile']}" />
</xsl:for-each>
</xsl:if>
It works to some degree, but it takes all images, both those defined on the current page, and those on the parent page. Thats not really what i want. If toppic is defined on the current page, it shouldnt look to the parent...
Any help appriciated :)
Dont you just need to write something like
<xsl:for-each select="$currentPage/ancestor-or-self::node/data[@alias='toppic']">
<img src="yourmediacodeinhere" />
</xsl:for-each>
Won't that do?
/Jan
Otherwise this might do the trick:
I used this before to use some content from the parent node if it wasn't present on the current node. It's not the most beautiful XSLT I have written, but it worked in my case :)
/Kim A
I ended up with this
<xsl:choose>
<xsl:when test="string($currentPage/data [@alias='toppic']) != ''">
<xsl:variable name="documentNodeSet" select="$currentPage/data[@alias='toppic']"/>
<xsl:for-each select="$documentNodeSet/descendant::node">
<img alt="{umbraco.library:GetMedia(current(), 'false')/data [@alias='imgTitle']}" src="{umbraco.library:GetMedia(current(), 'false')/data [@alias='umbracoFile']}" />
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="documentNodeSet" select="$currentPage/ancestor::node/data[@alias='toppic']"/>
<xsl:for-each select="$documentNodeSet/descendant::node">
<img alt="{umbraco.library:GetMedia(current(), 'false')/data [@alias='imgTitle']}" src="{umbraco.library:GetMedia(current(), 'false')/data [@alias='umbracoFile']}" />
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
is working on a reply...