I have a macro setup to display the content (Title / Body text) for each sub-section under the text page. What I'm trying to do now is get the image thumbnails for each sub-section gallery to display under the body text. At the moment the macro below will display the same images i.e image1, image2, image3,image4 etc under each sub-section.
I think you're going to need to change "ancestor-or-self::node" to "descendant-or-self::node". It's currently walking the nodetree upwards, but you want to look downwards to the children (descendants).
Thanks for your help. I changed from ancestor to descendant but this didn't make any difference, the output was the same. The sub-sections are being correctly displayed underneath the text page.
Are you sure that the currentPage is one of your textpages? And if so, that there are different images linked under each gallery?
You could have a look at the XML you're getting in the currentPage, something might be wonky there. Right before the xsl:for-each you can put this call, it should output the full xml for the current page:
<node id="1124" version="fdc63e0f-104a-49a7-bf48-2d0d44a1fb90" parentID="1114" level="3" writerID="0" creatorID="0" nodeType="1081" template="1069" sortOrder="2" createDate="2010-01-10T17:16:39" updateDate="2010-01-31T22:25:05" nodeName="Lantern Launchs" urlName="lantern-launchs" writerName="Administrator" creatorName="Administrator" nodeTypeAlias="CWS_Textpage" path="-1,1091,1114,1124">
<node id="1160" version="5e34f54c-f507-438a-b7ce-eef7909aaad8" parentID="1124" level="4" writerID="0" creatorID="0" nodeType="1076" template="1061" sortOrder="1" createDate="2010-01-31T22:18:43" updateDate="2010-01-31T22:20:29" nodeName="Gallery" urlName="gallery" writerName="Administrator" creatorName="Administrator" nodeTypeAlias="CWS_Gallery" path="-1,1091,1114,1124,1160">
<data alias="galleryThumbnail" />
<node id="1161" version="f3e08f8e-e095-4c41-a32b-edf6be5d65b9" parentID="1160" level="5" writerID="0" creatorID="0" nodeType="1080" template="1066" sortOrder="1" createDate="2010-01-31T22:19:13" updateDate="2010-02-01T21:22:12" nodeName="Lantern1" urlName="lantern1" writerName="Administrator" creatorName="Administrator" nodeTypeAlias="CWS_Photo" path="-1,1091,1114,1124,1160,1161">
<data alias="photoText">Lantern</data>
<data alias="umbracoFile">/media/2165/ist2_8378271-table-set-for-an-event-party.jpg</data>
<data alias="umbracoNaviHide">0</data>
<data alias="Crops">
<crops date="31/01/2010 23:01:42">
<crop name="sectionPhoto" x="3" y="0" x2="373" y2="271" url="/media/2165/ist2_8378271-table-set-for-an-event-party_sectionPhoto.jpg" />
<crop name="large" x="11" y="0" x2="372" y2="271" url="/media/2165/ist2_8378271-table-set-for-an-event-party_large.jpg" />
<crop name="gallerythumb" x="63" y="4" x2="309" y2="250" url="/media/2165/ist2_8378271-table-set-for-an-event-party_gallerythumb.jpg" /></crops>
</data>
</node>
</node>
<data alias="umbracoNaviHide">0</data>
<p>Lantern Launches</p>
</data>
<data alias="articlePhoto" />
<data alias="bodyText">
<p>Lanterns can be used as a quiet alternative to fireworks for a
gentler celebration at New Year, Weddings, Birthdays, Halloween,
Bonfire Night, Diwali or any other special event. A lantern will
rise for up to 20 minutes and can ascend to over a mile in the sky
- where it will still be visible on a clear night!</p>
<p>Traditionally used in Chinese and Thai celebrations, these are a
beautiful and fascinating way to light up the sky that's becoming
increasingly popular.</p>
<p>At Total party hire we offer both diy or professional service.
You can take control, we sell diy packs of 10, 25,50 and 100 latern
packs. With our professional option, we do all the work and
fill the sky with however many fire lanterns you would like to
create a magical effect.</p>
</data>
</node>
So you can see that the current page (node 1114) has 2 sub-sections (nodes 1119 & 1124)
Each sub-section node has a hidden gallery (node 1150 or 1160)
Gallery (node 1150) has 4 images (nodes 1151,1157,1158 & 1159)
Gallery (node 1160) has only 1 image (node 1161)
The problem is that each sub-section is outputting to the unordered list all 5 images.
Help with XSLT and image thumbnails
My site structure is like this:
Home
- Text Page
-Sub section 1
- Gallery1
-Image1
-Image2
-Sub section 2
- Gallery2
-Image3
-Image4
- Text Page 2
-Sub section 3
- Gallery3
-Image5
-Image6
-Sub section 4
- Gallery4
-Image7
-Image8
I have a macro setup to display the content (Title / Body text) for each sub-section under the text page. What I'm trying to do now is get the image thumbnails for each sub-section gallery to display under the body text. At the moment the macro below will display the same images i.e image1, image2, image3,image4 etc under each sub-section.
<xsl:param name="currentPage"/>
<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="2"/>
<xsl:variable name="documentTypeAlias" select="string('CWS_Photo')"/>
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
<div class="subsection">
<h3 class="bg"><xsl:value-of select="umbraco.library:StripHtml(data [@alias='headerText'])"/></h3>
<xsl:value-of select="data [@alias = 'bodyText']" disable-output-escaping="yes" />
<ul class="photolist">
<xsl:for-each select="$currentPage//node [@nodeTypeAlias = $documentTypeAlias and string(data [@alias='umbracoNaviHide']) != '1']">
<li class="left">
<a href="{concat(substring-before(data [@alias='umbracoFile'],'.'), '_large.jpg')}"><img src="{concat(substring-before(data [@alias='umbracoFile'],'.'), '_galleryThumb.jpg')}" alt="{data [@alias = 'photoText']}" /></a>
</li>
</xsl:for-each>
</ul>
</div>
</xsl:for-each>
</xsl:template>
can one of the admin's put the formatting around my code.. sorry.
I think you're going to need to change "ancestor-or-self::node" to "descendant-or-self::node". It's currently walking the nodetree upwards, but you want to look downwards to the children (descendants).
Thanks for your help. I changed from ancestor to descendant but this didn't make any difference, the output was the same. The sub-sections are being correctly displayed underneath the text page.
This is the XSLT that doesn't work properly:
The list of image thumbnails under each sub-section is the same, I need the for-each to select only the images underneath its respective sub-section.
Hmm..
Are you sure that the currentPage is one of your textpages? And if so, that there are different images linked under each gallery?
You could have a look at the XML you're getting in the currentPage, something might be wonky there. Right before the xsl:for-each you can put this call, it should output the full xml for the current page:
Right, I've added Sebastiaan's code above just before the for each loop and this is what I get:
and the next sub-section outputs this:
So you can see that the current page (node 1114) has 2 sub-sections (nodes 1119 & 1124)
Each sub-section node has a hidden gallery (node 1150 or 1160)
Gallery (node 1150) has 4 images (nodes 1151,1157,1158 & 1159)
Gallery (node 1160) has only 1 image (node 1161)
The problem is that each sub-section is outputting to the unordered list all 5 images.
You probably need to use <xsl:for-each select="current()/node..... in your inner loop.
The current() will get the node that you are currently looping in the outer loop, and navigate further down from there.
This seemsto have fixed it. Thanks everyone for their help.
is working on a reply...