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'])" />
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.
<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.
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?
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
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:
Hope this helps...
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.
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
[@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
Nice work Dennis...
Thanks very much. That seems very thorough.
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"/>
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
Yep, there you go. You guys been really cool with the response time and quality. Thanks a bunch.
Nice work mate...
is working on a reply...
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.