Possible to check if a node is published or not in XSLT?
On one of my sites, the user can use some of the same content on a lot of different pages, so the same content can be used over and over againg, without creating the same content more than one time.
But if a node is choosen on another node, and the imported node is unpublished, the site layout f***'s up, because the imported, unpublished, nodeID still figures as one of the nodes who should be rendered on the site. On all of my pages, I use the multiple tree picker, to choose the nodes that can be imported on that page.
But is there some way in Umbraco/XSLT to find out, if a node is published or not?
I hope this makes sense to you folks. It actually work pretty perfect, and is easy for the webmasters to use. Just a little difficult to describe in words :D
XSLT *only* has access to published nodes, so when you request a node id that is now unpublished it will either give an error or fail silently. My guess is that you have a for-each loop on all of the node id's. You'll just want to check that each nodeid actually has some content in it... which means it is currently published.
I can think of a couple ways to do this. One would be to check a propertie's content, such as bodyText. Another would be to get the NiceUrl(). Another would be to do a GetXmlNodeById(). I'm sure there are others.
The important thing is to check the result with the string() != '' syntax one see's everywhere. This will ensure the macro doesn't give an error if the node isn't published.
instead as I was also looking to see if the property was empty even if it was published (I am using the related links datatype and needed to check if content was available on the linked pages). This does work.
Possible to check if a node is published or not in XSLT?
On one of my sites, the user can use some of the same content on a lot of different pages, so the same content can be used over and over againg, without creating the same content more than one time.
But if a node is choosen on another node, and the imported node is unpublished, the site layout f***'s up, because the imported, unpublished, nodeID still figures as one of the nodes who should be rendered on the site. On all of my pages, I use the multiple tree picker, to choose the nodes that can be imported on that page.
But is there some way in Umbraco/XSLT to find out, if a node is published or not?
I hope this makes sense to you folks. It actually work pretty perfect, and is easy for the webmasters to use. Just a little difficult to describe in words :D
If a node exists in the XML then it is published. You could always check if the node exists with something like
or
XSLT *only* has access to published nodes, so when you request a node id that is now unpublished it will either give an error or fail silently. My guess is that you have a for-each loop on all of the node id's. You'll just want to check that each nodeid actually has some content in it... which means it is currently published.
I can think of a couple ways to do this. One would be to check a propertie's content, such as bodyText. Another would be to get the NiceUrl(). Another would be to do a GetXmlNodeById(). I'm sure there are others.
The important thing is to check the result with the string() != '' syntax one see's everywhere. This will ensure the macro doesn't give an error if the node isn't published.
Shout if you need a code sample.
cheers,
doug.
OR
<xsl:if test="string-length(umbraco.library:GetXmlNodeById('1088')/error) > 0">
Error
</xsl:if>
:-)
Thanks. I'll try out your examples in one of the days :)
I had the same problem I've tried Chris' example and it seems not to work for what I was doing. eg
This seems to be because GetXmlNodeById() will return something like "The is no published content for node xxx" so the count will be 1 regardless.
I did not try Ronnie's method though as I just modified the above to test
instead as I was also looking to see if the property was empty even if it was published (I am using the related links datatype and needed to check if content was available on the linked pages). This does work.
Hope it helps :)
is working on a reply...