As you can see, there are two album nodes, one for images one for videos. What I try to do is to check video or image field. For example if in June there is not any video, then only display image album node.
After searching on umbraco, I could not find a solution so far...
A great way to do this with XSLT is to define separate templates for the video and image types, and then just process each type individually - something like this:
But based on following structure I placed a macro on "Flash" node.
- Flash
- June
- Picture
- Picture
- July
- Pictures
- Video
I gave it a try from this link XPATH Axes and their Shortcuts but with this code snippet, I can only reach till June node. How can I go deeper and check child nodes of June or July.
How to check a field
Hi everyone,
I have such structure...
- Flash
- June
- Picture
- Picture
- July
- Pictures
- Video
using an xslt file which turns infos into an xml file.
<gallery title="Standalone example" description="Slideshow example demonstrating event listeners."> <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']"> <album lgPath="http://localhost" tnPath="http://localhost" title="{./data [@alias = 'albumTitle']}" description="{./data [@alias = 'albumDescription']}"> <xsl:for-each select="node"> <img src="{./data [@alias = 'image']}" title="{./data [@alias = 'title']}" caption="{./data [@alias = 'caption']}" link="{./data [@alias = 'link']}" target="_blank" pause="" /> </xsl:for-each> </album> <album lgPath="http://localhost" tnPath="http://localhost" title="Album Two" description="Video example"> <xsl:for-each select="node"> <img src="{./data [@alias = 'video']}" tn="/flash/gallery/album2/thumb/1.jpg" title="" caption="" link="" target="_blank" pause=""/> </xsl:for-each> </album></gallery>
As you can see, there are two album nodes, one for images one for videos. What I try to do is to check video or image field. For example if in June there is not any video, then only display image album node.
After searching on umbraco, I could not find a solution so far...
<xsl:if test="string(./data [@alias='video']) != ''"> <album lgPath="http://localhost" tnPath="http://localhost" title="Album Two" description="Video example" tn="http://localhost/flash/gallery/album1/preview.jpg"> <xsl:for-each select="node"> <img src="{./data [@alias = 'video']}" tn="/flash/gallery/album2/thumb/1.jpg" title="" caption="" link="" target="_blank" pause=""/> </xsl:for-each> </album> </xsl:if>I tried with xsl:if but did not work out.
Hi ds,
A great way to do this with XSLT is to define separate templates for the video and image types, and then just process each type individually - something like this:
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:umbraco.library="urn:umbraco.library" exclude-result-prefixes="umbraco.library" > <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" /> <xsl:param name="currentPage" /> <xsl:template match="/"> <gallery title="Standalone example" description="Slideshow example demonstrating event listeners."> <xsl:if test="node[data[@alias = 'image']][not(data[@alias = 'umbracoNaviHide'] = 1)]"> <album lgPath="http://localhost" tnPath="http://localhost" title="{data[@alias = 'albumTitle']}" description="{data[@alias = 'albumDescription']}"> <!-- Process all images --> <xsl:apply-templates select="node[data[@alias = 'image']]" /> </album> </xsl:if> <xsl:if test="node[data[@alias = 'video']][not(data[@alias = 'umbracoNaviHide'] = 1)]"> <album lgPath="http://localhost" tnPath="http://localhost" title="Album Two" description="Video example"> <!-- Process all videos --> <xsl:apply-templates select="node[data[@alias = 'video']]" /> </album> </xsl:if> </gallery> </xsl:template> <!-- Template for images --> <xsl:template match="node[data[@alias = 'image']]"> <img src="{data[@alias = 'image']}" title="{data[@alias = 'title']}" caption="{data[@alias = 'caption']}" link="{data[@alias = 'link']}" target="_blank" pause="" /> </xsl:template> <!-- Template for Videos --> <xsl:template match="node[data[@alias = 'video']]"> <img src="{data[@alias = 'video']}" tn="/flash/gallery/album2/thumb/1.jpg" title="" caption="" link="" target="_blank" pause="" /> </xsl:template> <!-- Empty template for hidden nodes --> <xsl:template match="node[data[@alias = 'umbracoNaviHide'] = 1]" /> </xsl:stylesheet>/Chriztian
Hi Chriztian,
I made some changes on your code snippet,
<gallery title="Standalone example" description="Slideshow example demonstrating event listeners."> <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']"> <xsl:if test="node[data[@alias = 'image']]"> <album lgPath="http://localhost" tnPath="http://localhost" title="{data[@alias = 'albumTitle']}" description="{data[@alias = 'albumDescription']}"> <!-- Process all images --> <xsl:for-each select="node"> <xsl:apply-templates select="node[data[@alias = 'image']]" /> </xsl:for-each> </album> </xsl:if> <xsl:if test="node[data[@alias = 'video']]"> <album lgPath="http://localhost" tnPath="http://localhost" title="Album Two" description="Video example"> <!-- Process all videos --> <xsl:for-each select="node"> <xsl:apply-templates select="node[data[@alias = 'video']]" /> </xsl:for-each> </album> </xsl:if> </xsl:for-each> </gallery>
But based on following structure I placed a macro on "Flash" node.
- Flash
- June
- Picture
- Picture
- July
- Pictures
- Video
I gave it a try from this link XPATH Axes and their Shortcuts but with this code snippet, I can only reach till June node. How can I go deeper and check child nodes of June or July.
Hi ds,
You can use the descendant:: axis (//) for this, e.g.:
- will select all nodes below $currentPage which has the 'image' property, regardless of level
If you want to group by month you could add another for-each inside, e.g.:
/Chriztian
Hi Chriztian,
Even though I tried with your code snippet, It does not give me the result.
Let me ask you in another way.
For such an outpout from xslt in the following, what should I do?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.