I have searched around for how to handle comma seperated lists, but they all look more advanced (i think) than what i need. Also i mostly dont understand the solutions 100%.
Let me explain it very quick first:
I have one page with a simple UL list that contains a bunch of links. Categories. Those links have a series of number appended to the url, so the result is: www.mysite.com/categorylist/itemlist?categoryId=118,123,113,108,103 Other links have fewer or more numbers.
That "itemlist" (its just a made up name for this case) is supposed to show the contents from the chosen category and the xslt is supposed to recieve that series of numbers, and looks for all the items that contains those numbers from a webservice xml.
I know how to do everything EXCEPT splitting up the id's and also "for-eaching" for items that contains those numbers.
To split the list, you can use umbraco.library:Split() which will give you a values element with a value for every value (ahem :-) in the list - you can throw that in a for each right away:
<!-- Grab a reference to the Top level node in the site -->
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<!-- Select the parent of all the nodes that should be included in the search for categories -->
<xsl:variable name="source" select="$siteRoot/News" />
<!-- Get the list from QueryString -->
<xsl:variable name="itemlist" select="umbraco.library:RequestQueryString('categoryId')" />
<!-- Split and Go -->
<xsl:for-each select="umbraco.library:Split($itemlist, ',')//value">
<xsl:apply-templates select="$source//*[@isDoc][contains(concat('|', categories, '|', concat('|', current(), '|')]" />
</xsl:for-each>
<!-- Template for a node that contains the categoryId -->
<xsl:template match="*[@isDoc]">
<p>
<xsl:value-of select="@nodeName" />
</p>
</xsl:template>
(The fiddly stuff with the concat() and the pipes are to ensure that an item with the category 1234 doesn't get selected when the categories12, 23, 234 etc. are selected.)
Thanks! I think its almost there, the only difference being im not looking for umbraco nodes but xml nodes from a webservice.
Normally it would look like this:
<xsl:for-each select="$Service/ArrayOfJob/Job"> <li>item name for example goes here</li> </xsl:for-each>
Service is the webservice, and the nodes in that xml each contain a different category id. And i need a list of all those coresponding to the comma list.
which, doesnt work. I am sure im missing something somewhere... maybe im just navigating the xml wrong. it does recieve the "categoryName" and display it so something is at least working. the list is just empty. Gotta experiment some more but suggestions are helpful.
Oh and excuse the lack of proper code formatting, but the forum is acting up.
Sorry for bumping, but the issue is becoming increasingly urgent, and i believe the error is a mere oversight but my knowledge about this particular subject is lacking to say the least.
Also, that editing and other function on this forum doesnt work isnt helping. Sorry about that.
The way you perform the test, the processor will take the first value element as the right hand side of the test. Also: you're doing the same Split() on every iteration - waste of cycles :-)
First, put the result of the Split() into a handy variable; Then use that variable in a slightly modified version of the test:
Sorry for the lack of formatting, but the forum wont cooperate. Anyway, ive tested the values of "value" and everything comes out correctly. But the code above does not work. somewhat, ive narrowed it down to the [CategoryID = $values/value] because if i set the CategoryID to a hardcoded value it spits out the correct data. So the solution must be very close.
I tried that, and it didnt output anything, thats why i changed it to /value, which did output the correct values. But the loop doesnt work. Very odd indeed... i tried for having two "for-each" loops, which didnt worker either. Im sure i missed something simple...
either way, looks like it ended up with some xpath confusion, but regardless i wouldnt have been able to come this far without help, so i deeply appreciate it.
I am glad that there are so many willing to help "noobs" like me :)
Comma seperated lists and looping
I have searched around for how to handle comma seperated lists, but they all look more advanced (i think) than what i need. Also i mostly dont understand the solutions 100%.
Let me explain it very quick first:
I have one page with a simple UL list that contains a bunch of links. Categories. Those links have a series of number appended to the url, so the result is: www.mysite.com/categorylist/itemlist?categoryId=118,123,113,108,103
Other links have fewer or more numbers.
That "itemlist" (its just a made up name for this case) is supposed to show the contents from the chosen category and the xslt is supposed to recieve that series of numbers, and looks for all the items that contains those numbers from a webservice xml.
I know how to do everything EXCEPT splitting up the id's and also "for-eaching" for items that contains those numbers.
Hi Frederik,
To split the list, you can use umbraco.library:Split() which will give you a values element with a value for every value (ahem :-) in the list - you can throw that in a for each right away:
(The fiddly stuff with the concat() and the pipes are to ensure that an item with the category 1234 doesn't get selected when the categories12, 23, 234 etc. are selected.)
/Chriztian
Thanks! I think its almost there, the only difference being im not looking for umbraco nodes but xml nodes from a webservice.
Normally it would look like this:
<xsl:for-each select="$Service/ArrayOfJob/Job">
<li>item name for example goes here</li>
</xsl:for-each>
Service is the webservice, and the nodes in that xml each contain a different category id. And i need a list of all those coresponding to the comma list.
so this is what im at now:
<ul data-role="listview" data-inset="true">
<li data-role="list-divider"><xsl:value-of select="$categoryName"/></li>
<xsl:for-each select="$Service/ArrayOfJob/Job">
<xsl:if test="Categories/JobCategory/CategoryID = umbraco.library:Split($categoryCsl, ',')//value">
<li><a><xsl:attribute name="href">#</xsl:attribute><xsl:value-of select="Name"/><span class="ui-li-count">10</span></a></li>
</xsl:if>
</xsl:for-each>
</ul>
which, doesnt work. I am sure im missing something somewhere... maybe im just navigating the xml wrong. it does recieve the "categoryName" and display it so something is at least working. the list is just empty. Gotta experiment some more but suggestions are helpful.
Oh and excuse the lack of proper code formatting, but the forum is acting up.
Sigh, cant edit my post.
but a correction: my code DOES work, but it only takes the first ID in the comma string.
Sorry for bumping, but the issue is becoming increasingly urgent, and i believe the error is a mere oversight but my knowledge about this particular subject is lacking to say the least.
Also, that editing and other function on this forum doesnt work isnt helping. Sorry about that.
Hi Frederik,
The way you perform the test, the processor will take the first value element as the right hand side of the test. Also: you're doing the same Split() on every iteration - waste of cycles :-)
First, put the result of the Split() into a handy variable; Then use that variable in a slightly modified version of the test:
Hope it helps - otherwise, come back again!
/Chriztian
Thank you for your reply, this is what i have:
<xsl:variable name="values" select="umbraco.library:Split($categoryCsl, ',')/value" />
<xsl:template match="/">
<ul data-role="listview" data-inset="true">
<li data-role="list-divider">
<xsl:value-of select="$categoryName" />
</li>
<xsl:for-each select="$Service/ArrayOfJob/Job">
<xsl:if test="Categories/JobCategory[CategoryID = $values/value]">
<li>
<a href="#">
<xsl:value-of select="Name" />
<span class="ui-li-count">10</span>
</a>
</li>
</xsl:if>
</xsl:for-each>
</ul>
Sorry for the lack of formatting, but the forum wont cooperate. Anyway, ive tested the values of "value" and everything comes out correctly. But the code above does not work. somewhat, ive narrowed it down to the [CategoryID = $values/value] because if i set the CategoryID to a hardcoded value it spits out the correct data. So the solution must be very close.
Hi Frederik,
Note that I put values (plural) on the end of the call to Split() - you're using the singular value.
Split() returns an XML chunk like this:
So by assigning the $values variable directly to the "values" element enables using XPaths like "$values/value" to select the stuff you need.
/Chriztian
I tried that, and it didnt output anything, thats why i changed it to /value, which did output the correct values. But the loop doesnt work. Very odd indeed... i tried for having two "for-each" loops, which didnt worker either. Im sure i missed something simple...
Ok, looks like it is working, to be honest im not 100% of the reason, but this is what i came up with:
either way, looks like it ended up with some xpath confusion, but regardless i wouldnt have been able to come this far without help, so i deeply appreciate it.
I am glad that there are so many willing to help "noobs" like me :)
is working on a reply...