Copied to clipboard

Flag this post as spam?

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


  • bob baty-barr 1180 posts 1294 karma points MVP
    Jun 19, 2011 @ 20:27
    bob baty-barr
    0

    having trouble getting nodeset count using match templates

    hello all! i have recently started trying to adopt some smarter xslt syntax but have no idea how to get a count of items when using match statements for templates...

    for example,

    <xsl:param name="currentPage"/>
      
      <!-- Input the related links property alias here -->
      <xsl:variable name="propertyAlias" select="string('literatureAssociations')"/>
      <xsl:variable name="maxShow" select="15"/>
        <xsl:variable name="showAll" select="umb:Request('showAll')"/>
      
      <xsl:template match="/">
        <xsl:apply-templates select="." mode="media.all" />
      </xsl:template>
      
      <!-- Template for media that needs fetching - handles potential error -->
    <xsl:template match="*" mode="media.all">
      <xsl:variable name="mediaNode" select="umb:GetMedia(1597, true())/*" />
      <xsl:if test="$mediaNode/*[contains(literatureAssociations, $currentPage/@id)]">
      <h3>Related Literature</h3>
      <ul id="relatedLiterature">
        
        <xsl:apply-templates select="$mediaNode[not(error)]" />
           
      </ul>
      </xsl:if>
    </xsl:template>
        
      <!-- The fun starts here -->
      <!-- Template for a Media File -->
      <xsl:template match="File">
        
        
    <xsl:if test="contains(literatureAssociations, $currentPage/@id)">
      
    <li class="file">
      
      <!-- add tool tip -->
      <a>
        <xsl:attribute name = "href">
          <xsl:value-of select="umbracoFile"/>
        </xsl:attribute>
        <xsl:attribute name="target">_blank</xsl:attribute>
        <xsl:attribute name="class">litLink</xsl:attribute>
        <span>
        <xsl:choose>
          <xsl:when test="literatureTitle!=''">
            <xsl:value-of select="literatureTitle" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="umbracoFile" />
          </xsl:otherwise>
        </xsl:choose>
      </span>
      </a>
      
        <xsl:choose>
          <xsl:when test="literatureDescription !=''">
            <div class="tooltip">
              <xsl:value-of select="literatureDescription"/> <br/>[File Size: <xsl:value-of select="format-number(umbracoBytes div 1024,'#,###')" /> kb]
            </div>
          </xsl:when>
          <xsl:otherwise>
            <div class="tooltip">
              <xsl:value-of select="literatureTitle"/> <br/>[File Size: <xsl:value-of select="format-number(umbracoBytes div 1024,'#,###')" /> kb]
            </div>
          </xsl:otherwise>
      </xsl:choose>


      
    </li>
      
    </xsl:if>
    </xsl:template>


    above, i would love to only show the first x-number of media files [actual File] but i have no idea where to check the count...

    <!-- Template for a Media File -->
      <xsl:template match="File">

     

    any help would be greatly appreciated :)

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 19, 2011 @ 20:51
    Tom Fulton
    0

    So this is what you're doing at your hotel all night? :)

    Inside your File template you should have access to position() to do something like:

    <xsl:template match="File">
    <xsl:if test="position() &lt; 10">
    ...
    </xsl:if>
    </xsl:template>

    Also something like this would seem to be a better way to do it, not sure if it works or not though:

    <xsl:apply-templates select="$mediaNode[not(error)][position() &lt; 10]" />

    ...paging Chriztian for corrections :)

    Hope this helps,
    Tom

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jun 19, 2011 @ 20:58
    bob baty-barr
    0

    one of the things i am doing, hoping it makes me sleep ;)

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jun 19, 2011 @ 21:00
    bob baty-barr
    0

    actually, this is what i was trying earlier in the week and it was not working... grrrr

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jun 19, 2011 @ 23:25
    Chriztian Steinmeier
    1

    Hi Bob (+ Tom)

    It's so close that it's almost too easy - the line that *should* work goes something like this:

    <xsl:apply-templates select="$mediaNode[not(error)]/File[position() &lt; $maxShow]" />

    - and I'll update this post with an explanation in a short while...

    /Chriztian

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 19, 2011 @ 23:46
    Tom Fulton
    0

    Ah yes, wrote that too fast :). Thanks Chriztian

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jul 18, 2011 @ 18:01
    bob baty-barr
    0

    along these same lines, i am trying to render a media tree and put a count of all FILES below folders... even if nested...

    for example, i have a folder, in it two other folders [in media] each of the nested folders contains 3 files...

    i need for the top folder to show 6 total files and each of the interior folders to show 3 files each... however, i am having difficulty targeting to count all files below where i currently am - to the end...

    (<xsl:value-of select="count(.//*[name() = 'File'])" /> Files)</span>

    obviously does not work, it goes two levels deep by default... any help??

  • Laurence Gillian 600 posts 1219 karma points
    Jul 18, 2011 @ 18:37
    Laurence Gillian
    1

    <xsl:value-of select="count(./descendant::*[name() = 'File']" />

    Reference - http://pimpmyxslt.com/axesviz.aspx?contextNode=1066&axis=descendant#screen

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jul 18, 2011 @ 18:43
    bob baty-barr
    0

    hey, just realized, it might help to have the section for matching folders in there...

    <!-- Template for a Media Folder -->
      <xsl:template match="Folder">
        <li>
          <!-- 1877 = technical papers media nodeid -->
          <xsl:choose>
            <xsl:when test="@id != '1877'">
              <xsl:attribute name="class">closed</xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:attribute name="class">open</xsl:attribute>
            </xsl:otherwise>
          </xsl:choose>

            
    <!--
          <span class="folder"><xsl:value-of select="@nodeName" /> (<xsl:value-of select="count(./*[name() = 'File'])" /> Files)</span>
    /sonnet/descendant-or-self::line
          
          <span class="folder"><xsl:value-of select="@nodeName" /> (<xsl:value-of select="count(descendant-or-self::*[name() = 'File'])" /> Files)</span>
    -->
          <span class="folder"><xsl:value-of select="@nodeName" /> (<xsl:value-of select="count(./descendant-or-self::*[name() = 'File'])" /> Files)</span>
        <ul>
          <xsl:apply-templates select="Folder" />
          <xsl:apply-templates select="File" />
        </ul>
    </li>

    </xsl:template>
  • bob baty-barr 1180 posts 1294 karma points MVP
    Jul 18, 2011 @ 18:50
    bob baty-barr
    0

    @Lau... that is so close, but check this out... if you expand the marketing materials folder, you will see it gives an odd result at the first sub folder... it should say 4 files as well???

    http://mtturl.ws/nsCGyv

     

  • Laurence Gillian 600 posts 1219 karma points
    Jul 18, 2011 @ 19:00
    Laurence Gillian
    0

    Very odd! That should get it, what happens if you do; Should work either way really...

    <xsl:value-of select="count(descendant::*[name() = 'File']" />

Please Sign in or register to post replies

Write your reply to:

Draft