Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Niklas Hjelm 104 posts 125 karma points
    Jan 23, 2011 @ 18:50
    Niklas Hjelm
    0

    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 "&#xA0;"> ]>
    <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>&amp;width=90</xsl:text>
                <xsl:text>&amp;compression=90</xsl:text>
                <xsl:text>&amp;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>




  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 23, 2011 @ 18:52
    Jan Skovgaard
    0

    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

  • 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.

Please Sign in or register to post replies