I have the following two xslt files which clearly could be merged into one because the only difference is one displays 3 recent items, the other, all items.
<!-- Template for the WebsitePreviewImage1 property --> <xsl:template match="WebsitePreviewImage1"> <xsl:variable name="media" select="umbraco.library:GetMedia(., false())" /> <img alt="{$media/@nodeName}" src="{$media/umbracoFile}" width="240" /> </xsl:template>
<!-- Template for an empty WebsitePreviewImage1 property --> <xsl:template match="WebsitePreviewImage1[not(normalize-space())]"> <img src="/images/rollback.png" alt="No preview available" width="240" /> </xsl:template>
Can anyone suggest how to merge the two. So far I have this, which doesn't, shows nothing at all on the hompage. Still trying to get my head round templates:
Merging two xslt files
Hi everyone,
I have the following two xslt files which clearly could be merged into one because the only difference is one displays 3 recent items, the other, all items.
XSLT 1
XSLT 2
Can anyone suggest how to merge the two. So far I have this, which doesn't, shows nothing at all on the hompage. Still trying to get my head round templates:
Thanks if anyone can shed some light :)
Sam.
give a flag value to decide how many items you want to display.
I used to do it by giving a number parameter.
number=0 //show all
Hi Sam,
That's a good use case for the mode attribute on templates - try this (important stuff highlighted):
<xsl:template match="/"> <ul id="portfolio-list"> <!-- Note that these are mutually exclusive with mode (scroll right!) --> <xsl:apply-templates select="$currentPage[@level = 1]/descendant-or-self::*[@isDoc]/PortfolioItem" mode="first3"> <xsl:sort select="@createDate" order="descending"/> </xsl:apply-templates> <xsl:apply-templates select="$currentPage[not(@level = 1)]/descendant-or-self::*[@isDoc]/PortfolioItem"> <xsl:sort select="@createDate" order="descending"/> </xsl:apply-templates> </ul> </xsl:template> <!-- Moded template for PortfolioItem elements --> <xsl:template match="PortfolioItem" mode="first3"> <xsl:if test="position() <= 3"> <li> <xsl:if test="position() mod 3 = 0"> <xsl:attribute name="class">last</xsl:attribute> </xsl:if> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:apply-templates select="WebsitePreviewImage1"/> </a> </li> </xsl:if> </xsl:template> <xsl:template match="PortfolioItem"> <li> <xsl:if test="position() mod 3 = 0"> <xsl:attribute name="class">last</xsl:attribute> </xsl:if> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:apply-templates select="WebsitePreviewImage1"/> </a> </li> </xsl:template> <!-- Template for the WebsitePreviewImage1 property --> <xsl:template match="WebsitePreviewImage1"> <xsl:variable name="media" select="umbraco.library:GetMedia(., false())"/> <img alt="{$media/@nodeName}" src="{$media/umbracoFile}" width="240"/> </xsl:template> <!-- Template for an empty WebsitePreviewImage1 property --> <xsl:template match="WebsitePreviewImage1[not(normalize-space())]"> <img src="/images/rollback.png" alt="No preview available" width="240"/> </xsl:template>
/Chriztian
Hi Chriztian,
I've seen you use the mode attribute before but never realised how or why to use it. Thanks a lot! Works perfectly :)
Sam.
is working on a reply...