I'm having some problems with one of my xslts. I'm trying to get the first image from a child from a page which I've selected using a Ultimate picker. I can get all items and I can get the last item. But when I try to use = or lesser than it returns nothing :( Could someone please help me out./ Thanks Niklas
Get first image from child
Hi
I'm having some problems with one of my xslts. I'm trying to get the first image from a child from a page which I've selected using a Ultimate picker. I can get all items and I can get the last item. But when I try to use = or lesser than it returns nothing :( Could someone please help me out./ Thanks Niklas
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="preNodes">
<xsl:variable name="relatedContent" select="$currentPage/relatedProducts" />
<xsl:variable name="nodeIds" select="umbraco.library:Split($relatedContent, ',')" />
<xsl:for-each select="$nodeIds/value">
<xsl:copy-of select="umbraco.library:GetXmlNodeById(.)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="nodes" select="msxml:node-set($preNodes)/*[@isDoc]" />
<xsl:if test="count($nodes) > 0">
<ul class="">
<xsl:for-each select="$nodes">
<li class="">
<xsl:value-of select="@nodeName"/>
</li>
</xsl:for-each>
<xsl:for-each select="$nodes/*">
<xsl:variable name="mediaId" select="number(articleImage)" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="$mediaNode/umbracoFile">
<li>
<img>
<xsl:attribute name="src">
<xsl:text>/umbraco/ImageGen.ashx?image=</xsl:text>
<xsl:value-of select="$mediaNode/umbracoFile" />
<xsl:text>&width=90</xsl:text>
<xsl:text>&compression=90</xsl:text>
<xsl:text>&constrain=true</xsl:text>
</xsl:attribute>
<xsl:attribute name="alt"><xsl:value-of select="$mediaNode/@nodeName" /></xsl:attribute>
<xsl:attribute name="class"></xsl:attribute>
</img>
</li>
</xsl:if>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Hi Niklas
In the loop that is used to fetch the image you need to add this inside it
<xsl:if test="position() = 1"><!-- rest of te code for getting the image goes here--></xsl:if>
This should do the trick for you.
/Jan
is working on a reply...