Copied to clipboard

Flag this post as spam?

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


  • Kory Doszpoly 19 posts 39 karma points
    Aug 07, 2012 @ 03:57
    Kory Doszpoly
    0

    Get List Count

    I'm trying to get the number of items in a list. This is covered elsewhere, but I can't get it to work. It returns '1' for some reason.

    <xsl:variable name="source" select="/macro/source"/>

    <xsl:value-of select="count(umbraco.library:GetXmlNodeById($source))" />

    What am I doing wrong?

  • Nigel Wilson 945 posts 2077 karma points
    Aug 07, 2012 @ 05:02
    Nigel Wilson
    0

    Hi Kory

    I assume the variable "source" is a node ID. If so then the count of 1 is correct as you are getting the node by using the ID.

    Are you able to expand on your explanation a bit - I do not fully understand what you are meaning by "number of items in a list". 

    Do you mean how many child nodes below the node you are using as the variable "source" ?

    Maybe your full xslt code would help also.

    Cheers, Nigel

  • Dan 1288 posts 3942 karma points c-trib
    Aug 07, 2012 @ 09:35
    Dan
    0

    Hi Kory,

    Nigel is quite right - your code will count the source node itself only, so it will always be 1.  To count the child nodes of that source node you'd do something like this:

    <xsl:value-of select="count(umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1'])" />

    Hope this helps...

  • Kory Doszpoly 19 posts 39 karma points
    Aug 07, 2012 @ 19:56
    Kory Doszpoly
    0

    Shoot, that worked. Yes, I meant the child nodes. (so new to Ubraco) 

    Would you mind explaining in detial (or pointing me to a resource that does) everything that goes on in this line of code? 

    Thanks.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 07, 2012 @ 20:33
    Dennis Aaen
    1

    Hi Kory,

    I hope it´s okay that I´m trying to explain what the line of code does

    What the line of code does is:

    <xsl:value-of select="count(umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide)!= '1'])"/>

    When you add the macro to your template you will have to pick at starting point (Source), So umbraco.library:GetXmlNodeById is one of many Umbraco exstensions, and this one will get the XML from the picked node. /* will point to picked node childs. So /* is the child nodes.

    The line below will do the same, but /* is the shortcut to get the child nodes.
    Here is an overview of the different axes and their shortcuts to get XML from umbraco http://our.umbraco.org/wiki/reference/xslt/xpath-axes-and-their-shortcuts

    <xsl:value-of select="count(umbraco.library:GetXmlNodeById($source)/child::* [@isDoc and string(umbracoNaviHide) != '1'])"/>

    [@isDoc] The "isDoc" attribute is there to identify documents (content nodes) otherwise they'd be properties, and the string(umbracoNaviHide!=1) makes it possible to hide nodes from a navigation for exmple. To be able to hide notes in Umbraco, you must create a property on your document type with the alias umbracoNaviHide and the data type need is true / false data type (which is a checkbox).

    As a completely new to Umbraco I recommend you see these Video folders.
    They show the most basic things in relation to work with Umbraco. I had the great benefit of seeing them through, when I started looking at Umbraco.And  I can only recommend it. http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco.aspx

    I hope this makes sense and is helpful and I haven´t written something wrong.

    /Dennis

  • Nigel Wilson 945 posts 2077 karma points
    Aug 07, 2012 @ 20:53
    Nigel Wilson
    0

    Nice work Dennis...

  • Kory Doszpoly 19 posts 39 karma points
    Aug 08, 2012 @ 00:31
    Kory Doszpoly
    0

    Thanks very much. That seems very thorough. 

  • Kory Doszpoly 19 posts 39 karma points
    Aug 08, 2012 @ 00:35
    Kory Doszpoly
    0

    Sorry, it's still a problem. How come this works:

    <xsl:value-of select="count(umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1'])" />

    But this does not:  

    <xsl:variable name="listCount" select="count(umbraco.library:GetXmlNodeById($source)/* [@isDoc and string(umbracoNaviHide) != '1'])"/>
    <xsl:value-of select="listCount"/> 

  • Nigel Wilson 945 posts 2077 karma points
    Aug 08, 2012 @ 00:43
    Nigel Wilson
    0

    Hi Kory

    A simple case of the missing $ sign - when outputting a variable you need prefix it with a $ sign.

    eg. <xsl:value-of select="$listCount"/> 

     

    Cheers, Nigel

  • Kory Doszpoly 19 posts 39 karma points
    Aug 08, 2012 @ 00:46
    Kory Doszpoly
    0

    Yep, there you go. You guys been really cool with the response time and quality. Thanks a bunch.

  • Nigel Wilson 945 posts 2077 karma points
    Aug 08, 2012 @ 01:32
    Nigel Wilson
    0

    Nice work mate...

  • 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