if you're in a loop you would do soemthing like....
<!-- where @id is the id of the current node in the loop --> <xsl:variable name="children" select="umbraco.library:GetXmlNodeById(@id)/node"/> <xsl:if test="count($children) > 0"> <!-- perform your actions here --> </xsl:if>
Depending on the context of the xslt, you don't always have to call the library method, you could just count the childnodes directly, i.e count($currentPage/node), or if you're in a loop, you could just as easy call count(./node) to count the children of the current node in the loop. Sometimes, the slight overhead of calling GetXmlNodeById can be avoided.
I try the count(./node) but it doesn't return any values. If I try count(./*) it does work. Any thoughts on this? Or is this related to versions? I'm working in 4.5 at the moment.
Is There A Check If Node Has Children Method?
I need to check if a node has child nodes and then do something? Is there something in the Umbraco.Library that checks this and returns a boolean?
Thanks in advance :)
if you're in a loop you would do soemthing like....
HTH,
Nik
Appreciated thanks :)
Depending on the context of the xslt, you don't always have to call the library method, you could just count the childnodes directly, i.e count($currentPage/node), or if you're in a loop, you could just as easy call count(./node) to count the children of the current node in the loop. Sometimes, the slight overhead of calling GetXmlNodeById can be avoided.
Stephan, good point.
I try the count(./node) but it doesn't return any values. If I try count(./*) it does work. Any thoughts on this? Or is this related to versions? I'm working in 4.5 at the moment.
is working on a reply...