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">
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...
@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???
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,
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...
any help would be greatly appreciated :)
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:
Also something like this would seem to be a better way to do it, not sure if it works or not though:
...paging Chriztian for corrections :)
Hope this helps,
Tom
one of the things i am doing, hoping it makes me sleep ;)
actually, this is what i was trying earlier in the week and it was not working... grrrr
Hi Bob (+ Tom)
It's so close that it's almost too easy - the line that *should* work goes something like this:
- and I'll update this post with an explanation in a short while...
/Chriztian
Ah yes, wrote that too fast :). Thanks Chriztian
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...
obviously does not work, it goes two levels deep by default... any help??
<xsl:value-of select="count(./descendant::*[name() = 'File']" />
Reference - http://pimpmyxslt.com/axesviz.aspx?contextNode=1066&axis=descendant#screen
hey, just realized, it might help to have the section for matching folders in there...
@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
Very odd! That should get it, what happens if you do; Should work either way really...
<xsl:value-of select="count(descendant::*[name() = 'File']" />
is working on a reply...