I have created a datatype from a checklist. This holds a number of different values that are essentially tags for one set of child nodes. This set of child nodes are 'Publication' nodes. Each publication can have multiple authors that are in the checkbox list.
What I would like as a final outcome is for a page called "Authors" where I can produce a list of links to each of the items for this list. When a user clicks on an author, is then goes to a page that lists all the nodes where they are ticked as a centre author.
I'm currently working on the first stage of this and have come up with what I think is the right approach (open to suggestion!) for what I want to achieve. I currently have a couple of problems:
The list is being produced as a string with commas, I guess I will need to use umbraco.library:Split to split the results up before doing some distinct selecting(?) Solving this by make the second problem void.
If I select author 1 and author 2 for he first publication and auhor 1 and author 2 for the second publication, I only get one result as it's reading the string, comparing it and as they're the same it's getting rid of one to make it distinct (which I guess is exactly what I've asked it to do!)
If anyone can help me out, I'd really appreciate it! Not sure if a better solution would be to read in the checklist iteself and pull out each of the values rather than looking through the nodes to see what values are assigned?
I'd like to help you out but I don't think I understand completely, so I'll post a question first:
Does the authors only "exist" as prevalues on a datatype or are they separate documents (which the checklist pulls in as prevalues)?
XSLT can do some very powerful lookups between large nodesets, but requires values to be nodes (as opposed to strings), so yes, you'll need to split the CSV data into nodes if you want to solve this in a good way.
Thanks a lot for your reply - What I have done is create a new datatype as a checkbox and popped the values in there. These values will change as more authors are added to the list.
To add the authors as nodes would you suggest I create a new document type as an author and then add each person as a node? If so, how could I then tie an author to a publication? Could I build a checkbox list out of existing nodes?
I've created some nodes under a new document type and used the ultimate picker tool, so now have a checkbox list filled with authors as nodes rather than a string.
Any further advice would be much appreciated and I'm now in unfamiliar territory!
Oh yes - depends a little on the version of Umbraco you're using, though - but if you have an "Authors" section with separate "Author" documents, you can set up an "Author Picker" datatype using the "XPath CheckBoxList" Property Editor, which can save the picked authors as XML, which makes it very easy to do any lookups between publications. Also, you'd have your distinct list of authors just by listing all the "Author" nodes created - maybe filtering on actually being picked on a publication, which would also be pretty straightforward...
Still, if you for some reason can't use this ultimate setup, it's of course possible to do what you need - just takes a little more work :-)
I can set it as a XPath CheckBoxList if that will make the process easier. Current setup below. Feel free to comment - I can set it up differently if need be. The site is still in development stage so can be changed as I go along.
Got a 'publicationHome' document type which can only have 'publication' children.
'publication' document types have a datatype available to them that is an ultimate picker with the top node set to list all children of 'centreAuthor'. This can be changed to XPath CheckBoxList with some guidance. :)
Got a 'centreAuthors' document type which can only have 'centreAuthor' children
So refresh my memory, how does the XML look for the Ultimate Picker? Is it a bunch of <value>1234</value><value>2039</value> nodes?
Not sure how I'd get that to show as a list.. I'm good at editing pre-existing code, but rubbish at writing it from scratch! I guess I'd need to select a publication node and then do a for loop to publish all values..? Or is the question much simpler than that?
Thanks a lot for this Chriztian - really appreciate this!
Not sure why, but Umbraco doesn't like line 33:
Error occuredError in XSLT at line 33, char 13 31: <strong><xsl:value-of select="@nodeName" /></strong> 32: <!-- List all publications this author is credited with: --> 33: >>> <xsl:apply-templates select="$publicationHome//publication[authors//value = $authorID]" /> <<< 34: </li> 35: </xsl:template>
Not sure if it's a syntax error or that something doesn't exist somewhere.. I've named my picker authors to fit in with the code and all nodes have correct aliases (well done!)
Output is just the contents of the h2.. I've gone into the test publications I have listed in the system and tagged a few of the centreAuthors fro mthe checklist on each of them, but still not working.
Using the textarea method you recomended earlier, I've managed to tweak the paths. When I've done the following it seems to point to the correct places:
Your screenshot shows your $siteRoot ("WTCGHR") at level 1, which makes the original paths correct ($siteRoot/publicationHome and $siteRoot/../centreAuthors) - but only if you're running the macro from a page within the $siteRoot site - so if you're running the macro in the XSLT Visualizer, make sure to select a $currentPage within that site.
Just to be clear: If you're getting an empty <ul/> it can only mean one of two things: Your "Centre Authors" document type alias is not centreAuthors OR your "Centre Author" document type alias is not centreAuthor.
What do you get if you dump the $authorsRoot variable? (<xsl:copy-of select="$authorsRoot" />)
Right, when you do the double-slash, you're getting the centreAuthors properties of the publication nodes below $siteRoot.
So this means that $authorsRoot does not select the root node of the authors - The alias is correct, as seen on your screenshot, so must be the path...
This one is way inefficient but it's guaranteed to get the right one, which is what we're after right now:
Translated from XPath into english: "Go from the current page up to the ancestor named 'root', then search every nook and cranny for a document named 'centreAuthors'. Grab a hold of that, and don't let go!"
If you get that exact result above, the author nodes below it are not published - they should appear in the XML too, if they're published; but I'm not sure if you've removed them for brevity...?
In fact, as long as you get an empty <ul/> the code never enters the template for a single author, which in turn means that there are no authors (published)...
/Chriztian
PS: THis is how you should use the Split() extension to get the referenced publications, when we get the rest working:
One more thing then I promise I'll leave you alone! :)
I've modifed that code slightly so that it now runs through and shows a list of Authors on the author page and creates a link with the author's ID. This ID is passed a querystring to the results page.
I've then used the code provided to run through the list and find any publications by the author using the string passed to that page.
It produces a list of publications as expected and this list is correct, but it's adding them to the list the same number times as there are authors in the checklist. I understand why it's doing it as it's running through all the authors and then building up a template. What I don't get is how to tweak it so it produces a list of publications produced by the author of the querystring. Code below:
<!-- Grab a reference to the site's root --> <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<!-- Point to the two "roots" relative to the $siteRoot --> <xsl:variable name="authorsRoot" select="$siteRoot/../centreAuthors" /> <xsl:variable name="pubRoot" select="$siteRoot/publicationHome" /> <xsl:variable name="selectedAuthor" select="umb:RequestQueryString('author')"/>
Selecting distinct values
Hi,
I have created a datatype from a checklist. This holds a number of different values that are essentially tags for one set of child nodes. This set of child nodes are 'Publication' nodes. Each publication can have multiple authors that are in the checkbox list.
What I would like as a final outcome is for a page called "Authors" where I can produce a list of links to each of the items for this list. When a user clicks on an author, is then goes to a page that lists all the nodes where they are ticked as a centre author.
I'm currently working on the first stage of this and have come up with what I think is the right approach (open to suggestion!) for what I want to achieve. I currently have a couple of problems:
If anyone can help me out, I'd really appreciate it! Not sure if a better solution would be to read in the checklist iteself and pull out each of the values rather than looking through the nodes to see what values are assigned?
Thanks,
Tom
bump :(
Hi Tom,
I'd like to help you out but I don't think I understand completely, so I'll post a question first:
XSLT can do some very powerful lookups between large nodesets, but requires values to be nodes (as opposed to strings), so yes, you'll need to split the CSV data into nodes if you want to solve this in a good way.
/Chriztian
Hi Chriztian,
Thanks a lot for your reply - What I have done is create a new datatype as a checkbox and popped the values in there. These values will change as more authors are added to the list.
To add the authors as nodes would you suggest I create a new document type as an author and then add each person as a node? If so, how could I then tie an author to a publication? Could I build a checkbox list out of existing nodes?
Thanks,
Tom
I've created some nodes under a new document type and used the ultimate picker tool, so now have a checkbox list filled with authors as nodes rather than a string.
Any further advice would be much appreciated and I'm now in unfamiliar territory!
Thanks,
Tom
Hi Tom,
Oh yes - depends a little on the version of Umbraco you're using, though - but if you have an "Authors" section with separate "Author" documents, you can set up an "Author Picker" datatype using the "XPath CheckBoxList" Property Editor, which can save the picked authors as XML, which makes it very easy to do any lookups between publications. Also, you'd have your distinct list of authors just by listing all the "Author" nodes created - maybe filtering on actually being picked on a publication, which would also be pretty straightforward...
Still, if you for some reason can't use this ultimate setup, it's of course possible to do what you need - just takes a little more work :-)
Which version of Umbraco are you using?
/Chriztian
Allright - great!
So refresh my memory, how does the XML look for the Ultimate Picker? Is it a bunch of
<value>1234</value><value>2039</value>
nodes?/Chriztian
Using version v6.2.1
I can set it as a XPath CheckBoxList if that will make the process easier. Current setup below. Feel free to comment - I can set it up differently if need be. The site is still in development stage so can be changed as I go along.
Got a 'publicationHome' document type which can only have 'publication' children.
'publication' document types have a datatype available to them that is an ultimate picker with the top node set to list all children of 'centreAuthor'. This can be changed to XPath CheckBoxList with some guidance. :)
Got a 'centreAuthors' document type which can only have 'centreAuthor' children
So refresh my memory, how does the XML look for the Ultimate Picker? Is it a bunch of
<value>1234</value><value>2039</value>
nodes?Not sure how I'd get that to show as a list.. I'm good at editing pre-existing code, but rubbish at writing it from scratch! I guess I'd need to select a publication node and then do a for loop to publish all values..? Or is the question much simpler than that?
Hi Tom - three ways to get to know the XML (listed in increasing preferred order):
In a macro, write the following code:
Install my XMLDump package :-)
/Chriztian
Okay - so here's a crude example of how to do the lookup once you have a connection between the two:
(Note that you may need to change a couple of XPaths and aliases, but we'll try to solve that along the way)
/Chriztian
Thanks a lot for this Chriztian - really appreciate this!
Not sure why, but Umbraco doesn't like line 33:
Not sure if it's a syntax error or that something doesn't exist somewhere.. I've named my picker authors to fit in with the code and all nodes have correct aliases (well done!)
Oh - my bad!
The $publicationHome variable doesn't exist - I called it $pubRoot, so that's what it should say there. I've fixed the code above, for anyone else...
/Chriztian
Cool. It validates fine now and saves okay.
Output is just the contents of the h2.. I've gone into the test publications I have listed in the system and tagged a few of the centreAuthors fro mthe checklist on each of them, but still not working.
Could it be something to do with where the nodes sit in the structure?
Hi Tom,
Yes - the XPaths need to select the right nodes. The ones I've written (provided the aliases are correct) assume the following structure:
So your "Home" and "Authors" nodes are both at level 1 (?)
That's just inferred from your screenshot, but I could be wrong (noooo??? :)
But maybe your Authors are really inside the site? In that case:
Change to this for the authorsRoot variable:
/Chriztian
No the first one is correct - Didn't want the Authors to inherit anything from the rest of the site..
Full node structure screenshot attached..
Using the textarea method you recomended earlier, I've managed to tweak the paths. When I've done the following it seems to point to the correct places:
Would that make sense?
The output for this one doesn't produce anything useful though.. I've tried different variations on /, /.. and // but nothing seems to work.. :(
Hi Tom,
Your screenshot shows your $siteRoot ("WTCGHR") at level 1, which makes the original paths correct (
$siteRoot/publicationHome
and$siteRoot/../centreAuthors
) - but only if you're running the macro from a page within the $siteRoot site - so if you're running the macro in the XSLT Visualizer, make sure to select a $currentPage within that site.Does that make sense to you?
/Chriztian
The macro is running on the Publications > By Author page so it should work.. Should it not? Debugging is the worst! :(
I'll put it back to how it was. The macro stops rendering at the following point:
It pops the h2 and the <ul> tags and then doesn't pop any more information in..
Well, well, well :-)
Two places for where stuff goes bonkers:
Do you get an empty
<ul />
in the source, or do you get an error message? (Use "view source" - not the dev console...)/Chriztian
Okay. I've check re-checked and checked again with the aliases and can't see anything wrong there.
And yes - it produces a <ul />
Ultimate picker returns a set of numerical values. If more than one is selected, they are comma seperated..
Just looked in the app_data umbraco.config - the Ultimate picker seems to be adding stuff to the nodes in the following format:
Not sure how helpful that is?
That's it, right there :-)
Alright - I'll come back with a fix...
/Chriztian
Hi Tom,
Just to be clear: If you're getting an empty
<ul/>
it can only mean one of two things: Your "Centre Authors" document type alias is notcentreAuthors
OR your "Centre Author" document type alias is notcentreAuthor
.What do you get if you dump the $authorsRoot variable? (
<xsl:copy-of select="$authorsRoot" />
)/Chriztian
Just double checked the two of them - both correct.
When I do a dump of that it doesn't display anything (just a blank space and then the footer html of the site)
If I do a dump using double slash:
i get the following:
Document types (just to make sure I'm not going insane!):
Hi Tom,
Right, when you do the double-slash, you're getting the centreAuthors properties of the publication nodes below $siteRoot.
So this means that $authorsRoot does not select the root node of the authors - The alias is correct, as seen on your screenshot, so must be the path...
This one is way inefficient but it's guaranteed to get the right one, which is what we're after right now:
Translated from XPath into english: "Go from the current page up to the ancestor named 'root', then search every nook and cranny for a document named 'centreAuthors'. Grab a hold of that, and don't let go!"
/Chriztian
I tried it and it didn't work so I had another look at the node itself..
I'm so, so sorry! Somehow it wasn't published anymore..
I've reverted back to your original code and that also works now (as you said it would)
That now produces the following:
All the centreAuthor nodes under that are published, but still not showing (just getting a <ul />)
So frustratingly close!!
Hi Tom,
If you get that exact result above, the author nodes below it are not published - they should appear in the XML too, if they're published; but I'm not sure if you've removed them for brevity...?
In fact, as long as you get an empty
<ul/>
the code never enters the template for a single author, which in turn means that there are no authors (published).../Chriztian
PS: THis is how you should use the Split() extension to get the referenced publications, when we get the rest working:
Bizarre. They were all published, but not working.I unpublished them all and then republished - works a treat now!
I've also added in the extra code you included at the bottom there and it all works beautifully.
Thank you so much for your help and support - it's very much appreciated.
Tom
Awesome!
You're welcome :)
/Chriztian
One more thing then I promise I'll leave you alone! :)
I've modifed that code slightly so that it now runs through and shows a list of Authors on the author page and creates a link with the author's ID. This ID is passed a querystring to the results page.
I've then used the code provided to run through the list and find any publications by the author using the string passed to that page.
It produces a list of publications as expected and this list is correct, but it's adding them to the list the same number times as there are authors in the checklist. I understand why it's doing it as it's running through all the authors and then building up a template. What I don't get is how to tweak it so it produces a list of publications produced by the author of the querystring. Code below:
Hi Tom,
If I understand correctly, you need to tweak it like this:
Change the root template (
match="/"
) to only show the selected author:Was that the desired output?
/Chriztian
Perfect! :D
is working on a reply...