My recent experience with Umbraco 4, is that GetXmlNodeById does not crash, but if you put the result into a variable it then hangs the site. If you do the following I did not experience an issue, whether the node is now unpublished or even deleted.
Doesn't obviously work with 4.5.1 if you have a doc type called 'error' (or you'd just have to check for the message inside as well). All in all though I think Richard's way is much nicer. :)
My way is probably easier if you just need a check, if you need alternative content you'd have to use a choose statement and then I would definitely go for Richard's one (also I really do like applying templates and using the mode setting, it's just more structured/separate/re-usable.
how to validate a node before getXmlNodeById?
How can I validate a node before getXmlNodeById?
because if you pass a node id which is not valid it will through an exception and break the xslt.
Any help is much appreciated
Ali
Where do you get the nodeId?
Almost all nodeId I used are from content node. So I havn't this type problem.
the problem comes into scene when an editor selects a node in content picker and after a while another editor will delete it
hope that makes sense.
My recent experience with Umbraco 4, is that GetXmlNodeById does not crash, but if you put the result into a variable it then hangs the site. If you do the following I did not experience an issue, whether the node is now unpublished or even deleted.
Hi ali,
if a node with the id can't be found something like this:
gets returned. So what I usually do is
Doesn't obviously work with 4.5.1 if you have a doc type called 'error' (or you'd just have to check for the message inside as well). All in all though I think Richard's way is much nicer. :)
Sascha
thanks Sascha and Richard.
Could you help me how I can apply one of the above solution to this? as this becomes complicated with templates?
Thanks in advance.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:Cultiv.MediaCache="urn:Cultiv.MediaCache" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Cultiv.MediaCache "> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="currentPage"/> <xsl:variable name="articles" select="$currentPage/data [@alias = 'relatedArticles']" /> <xsl:template match="/"> <xsl:if test="$articles != ''"> <xsl:variable name="articlesList" select="umbraco.library:Split($articles, ',')" /> <ul id="search-forms"> <xsl:for-each select="$articlesList/value"> <xsl:variable name="articleNodeId" select="." /> <xsl:variable name="articleXml" select="umbraco.library:GetXmlNodeById($articleNodeId)" /> <li> <a href="{umbraco.library:NiceUrl($articleXml/@id)}" title="{$articleXml/data[@alias='headerText']}"> <xsl:choose> <xsl:when test="$articleXml/data[@alias='headerText'] != ''"> <xsl:value-of select="$articleXml/data[@alias='headerText']" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$articleXml/@nodeName" /> </xsl:otherwise> </xsl:choose> </a> </li> </xsl:for-each> </ul> </xsl:if> </xsl:template> </xsl:stylesheet>Hi Ali,
my solution would look like this:
Richard's solution would then be:
Hope that helps and I haven't produced too many typos,
Sascha
wooooooow, Brilliant, great sascha.
You are the man. Actually I choose your solution seems to be easier :D
Cheers
Ali
Hehe :)
My way is probably easier if you just need a check, if you need alternative content you'd have to use a choose statement and then I would definitely go for Richard's one (also I really do like applying templates and using the mode setting, it's just more structured/separate/re-usable.
Have a great day,
Sascha
Hi all,
See the reference document here for more information: http://our.umbraco.org/wiki/reference/umbracolibrary/getxmlnodebyid-(1)
Cheers!
David
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.