<xsl:for-each select="Exslt.ExsltStrings:split($inputStr, ',')"> <xsl:variable name="str" select="text()"/> <xsl:for-each select="$pages [contains((data [@alias = 'tags']), $str)]"> // !!! I need something like a container to put my item in here.. </xsl:for-each> </xsl:for-each>
The code works fine, but I don't know how to put my two og more sets together, and then make a top 10 limit.
Annoyingly I didn't come up with a solution back then. Even more annoyingly, I've just come up to a part in a project where I need to do just this. I'll give it another shot and post back here if I get a solution.
If this has nothing to do with your problem then just ignore me!
Yes, as far I can read, It look likes you got the same problem, but you didn't make it work somehow back then?
Morten Bock
Thanks for your example, but still can't resolve the problem, or just don't know how to do it, have been trying searching for a working combining method without any luck..
Here is an example of my research, maybe you can get this one work, I couldn't.
This time I didn't have a choice, so I enlisted a bit of help from another guy in the office. Below I've included the xslt with a c# function that's working fine for me. I've added comments, just in case.
Note: This xslt is used for getting a list of all tags attached to uploaded files in a chosen folder of the media library, then displaying the tags in a list of uniques, each with the amount of times the tag appears recorded. It will be easily changed to apply to anywhere else you have used tags.
It's probably also worth mentioning that in this case I'm not using the "tags" datatype (it seems a bit flakey) and the tags are just comma separated values in a string.
<!-- Grab currently requested tag and save as variable 'filter' --> <xsl:variable name="filter"> <xsl:choose> <xsl:when test="string-length(umbraco.library:Request('tag')) > 0"> <xsl:value-of select="umbraco.library:Request('tag')"/> </xsl:when> <xsl:otherwise> <xsl:text>all</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:variable>
<!-- Does the currentpage have a chosen media folder? (using mediaPicker with alias documentMediaFolder) --> <xsl:if test="string($currentPage/data [@alias='documentMediaFolder']) != ''">
<!-- get the actual media node from the ID using getMedia --> <xsl:variable name="mediaFolder" select="umbraco.library:GetMedia($currentPage/data [@alias='documentMediaFolder'], 'true')" />
<!-- Build up a master list of tags for all documents within the selected folder
finished string will be of format: tag,tag2,tag,tag3,tag2,tag etc etc --> <xsl:variable name="mediaFolderTags"> <xsl:for-each select="$mediaFolder/node [string(data[@alias='fileTags']) != '']"><xsl:value-of select="current()/data[@alias='fileTags']" />,</xsl:for-each> </xsl:variable>
<!-- pass our list of comma separated tags to our DistinctValues function
This function returns xml of the format below, with unique tags and an attrubute showing the frequency with which the tag appears
public XmlDocument DistinctValues(String commaList) {
string[] arr = commaList.Split(','); var distinctCount = new ArrayList(arr.Length); var distinctNames = new ArrayList(arr.Length);
foreach(string str in arr) { if(string.IsNullOrEmpty(str)) { continue; } var index = distinctNames.IndexOf(str); if (index >= 0) { var currentCount = (int)distinctCount[index]; distinctCount[index] = currentCount + 1; } else { distinctNames.Add(str); distinctCount.Add(1); } }
var outPut = ""; for (var i = 0; i < distinctNames.Count; i++) { var name = distinctNames[i]; var count = distinctCount[i]; outPut += "<value count='" + count + "'>" + name + "</value>"; }
var xml = new XmlDocument(); xml.LoadXml("<values>" + outPut + "</values>"); return xml; } ]]>
it looks like what Morten is suggesting should work. Are you able to loop over your original nodes in several loops? If so, your code might look something like this:
<xsl:variable name="nodeSetVar"> <xsl:for-each select=""> <!-- loop out nodes from first XPath --> </xsl:for-each> <xsl:for-each select=""> <!-- loop out nodes from second XPath --> </xsl:for-each> ... </xsl:variable> <xsl:variable name="myNodeset" select="msxsl:node-set($nodeSetVar)"/> <xsl:for-each select="$myNodeset/values/value"> .... </xsl:for-each>
Daniel, are you using the tag datatype in umbraco? If your are, then there is actually a small set of library methods for the tags. Even one that gets all content with with a certain tag.
What a amazing thread we just got here, just perfect - After the example from Nik Wahlberg based on Morten Bock's code, i finally got my very nice solution.
And thanks Jacob Jensen, you did just help me with a very nice example of how to distinct in a wonderful way trough xslt.
Morten Bock - Nope, I'm not using the tag feature in umbraco, but my own meta keyword based solution, from my new blog based on umbraco, at dnohr.dk, which works perfect. Didn't used the Blog4Umbraco, because I did have to convert some old blog data from my old website, so it's just a better way to learn great stuff, by making my own blog system by my self.
Thanks everybody for sharing and helping, have a wonderful weekend! :-)
How to merge node results sets
Hello
Is it possible to merge/copy two or more node results sets together, or do I need another solution?
I have tried searching on the web, but didn't have any luck for my specific solution.
Here is my code..
The code works fine, but I don't know how to put my two og more sets together, and then make a top 10 limit.
Is this by any chance to create a list of unique tags from comma separated tag data for particular nodes? I had a similar problem a few months back -> http://forum.umbraco.org/yaf_postst9763_Getting-a-unique-list-from-comma-separated-values-in-xslt.aspx.
Annoyingly I didn't come up with a solution back then. Even more annoyingly, I've just come up to a part in a project where I need to do just this. I'll give it another shot and post back here if I get a solution.
If this has nothing to do with your problem then just ignore me!
Dan
Well, you can create a nodeset like this:
<xsl:variable name="myValues"> <values> <value>13</value> <value>22</value> <value>23</value> <value>30</value> <value>40</value> </values> </xsl:variable> <xsl:variable name="myNodeset" select="msxsl:node-set($myValues)"> <xsl:for-each select="$myNodeset/values/value"> .... </xsl:for-each>
And I think that somewhere in the Exslt extensions there is a method for combining two sets of nodes
dandrayne
Yes, as far I can read, It look likes you got the same problem, but you didn't make it work somehow back then?
Morten Bock
Thanks for your example, but still can't resolve the problem, or just don't know how to do it, have been trying searching for a working combining method without any luck..
Here is an example of my research, maybe you can get this one work, I couldn't.
http://www.stylusstudio.com/xsllist/200503/post91390.html
Please share, if any of you find or got a solution on this problem. Otherwise i can't make my "Related blogs" based on tags :-)
I dont really know what your are trying to accomplish, but following mortens example, maybe this is usefull
Else, please supply some xml, or describe further
/Jacob
Hi Daniel
This time I didn't have a choice, so I enlisted a bit of help from another guy in the office. Below I've included the xslt with a c# function that's working fine for me. I've added comments, just in case.
Note: This xslt is used for getting a list of all tags attached to uploaded files in a chosen folder of the media library, then displaying the tags in a list of uniques, each with the amount of times the tag appears recorded. It will be easily changed to apply to anywhere else you have used tags.
It's probably also worth mentioning that in this case I'm not using the "tags" datatype (it seems a bit flakey) and the tags are just comma separated values in a string.
Good luck,
Dan
http://pastebin.com/m79115495
Daniel,
it looks like what Morten is suggesting should work. Are you able to loop over your original nodes in several loops? If so, your code might look something like this:
Based on Mortens response above...
Daniel, are you using the tag datatype in umbraco? If your are, then there is actually a small set of library methods for the tags. Even one that gets all content with with a certain tag.
I am using that on my own blog.
It even takes a comma separated string:
getContentsWithTags('some,tags,here')
What a amazing thread we just got here, just perfect - After the example from Nik Wahlberg based on Morten Bock's code, i finally got my very nice solution.
And thanks Jacob Jensen, you did just help me with a very nice example of how to distinct in a wonderful way trough xslt.
Morten Bock - Nope, I'm not using the tag feature in umbraco, but my own meta keyword based solution, from my new blog based on umbraco, at dnohr.dk, which works perfect. Didn't used the Blog4Umbraco, because I did have to convert some old blog data from my old website, so it's just a better way to learn great stuff, by making my own blog system by my self.
Thanks everybody for sharing and helping, have a wonderful weekend! :-)
FYI, I also found this example and explanation useful as a supplement on this topic:
http://stackoverflow.com/questions/3442089/xsl-merge-elements-and-sort-by-date
is working on a reply...