Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have the following statement where i use a GetXmlNodeById to display to display the child nodes if there is any and if not to display a message.
Am not sure what am doing wrong or missing something.
<xsl:for-each select="umbraco.library:GetXmlNodeById($source)/*[@isDoc and string(umbracoNaviHide) != '1']"> <xsl:choose> <xsl:when test="count(./*[@isDoc and string(umbracoNaviHide) != '1']) >0"> <xsl:value-of select="somevalue"/> </xsl:when> <xsl:otherwise> Do something else </xsl:otherwise> </xsl:choose> </xsl:for-each>
Hi Fuji
What is the problem?
Is it that the "Do something else" message is getting displayed or that it is never displayed?
/Jan
Hey Fuji,
I think you want to move the <xsl:choose> outside of the for-each, otherwise the code inside the for-each will never be run if there are no child nodes from $source, right? Or are you actually looking for child nodes of childs of source?
How about...
<xsl:variable name="sourceXml" select="umbraco.library:GetXmlNodeById($source)" /><xsl:choose> <xsl:when test="count($sourceXml/*[@isDoc and string(umbracoNaviHide) != '1']) > 0"> <xsl:for-each select="$sourceXml/*[@isDoc and string(umbracoNaviHide) != '1']"> <xsl:value-of select="somevalue"/> </xsl:for-each> </xsl:when> <xsl:otherwise> Do something else (there are no children) </xsl:otherwise></xsl:choose>
-Tom
Hey Jan,
Well i just want to display the Child nodes of the selected source if there is any child and if not then the "Do something else"
Tom this is exactly what i was looking for.
Hi Fuji,
Set a variable to hold all the childnodes - do your for-each on that (or apply some templates).
If the variable is empty, nothing will happen.
Afterwards, do a simple if and print a message when the set was empty.
<xsl:variable name="$sourceChildren" select="umbraco.library:GetXmlNodeById($source)/*[@isDoc][not(umbracoNaviHide = 1)]" /> <xsl:for-each select="$sourceChildren"> <!-- Do stuff with the nodes --> </xsl:for-each> <xsl:if test="not($sourceChildren)"> <!-- There's no spider here... --> </xsl:if>
Also: No need to count, and no need to string() anything - like a Mac, "it just works" :-)
/Chriztian
I will give this a try as well. Thanks for the help @Tom, @Jan, @Chriztian
Hey Chriztian,
Works just fine.......thanks for this again.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Choose or otherwise
I have the following statement where i use a GetXmlNodeById to display to display the child nodes if there is any and if not to display a message.
Am not sure what am doing wrong or missing something.
Hi Fuji
What is the problem?
Is it that the "Do something else" message is getting displayed or that it is never displayed?
/Jan
Hey Fuji,
I think you want to move the <xsl:choose> outside of the for-each, otherwise the code inside the for-each will never be run if there are no child nodes from $source, right? Or are you actually looking for child nodes of childs of source?
How about...
-Tom
Hey Jan,
Well i just want to display the Child nodes of the selected source if there is any child and if not then the "Do something else"
Tom this is exactly what i was looking for.
Hi Fuji,
Set a variable to hold all the childnodes - do your for-each on that (or apply some templates).
If the variable is empty, nothing will happen.
Afterwards, do a simple if and print a message when the set was empty.
Also: No need to count, and no need to string() anything - like a Mac, "it just works" :-)
/Chriztian
I will give this a try as well. Thanks for the help @Tom, @Jan, @Chriztian
Hey Chriztian,
Works just fine.......thanks for this again.
is working on a reply...