You should be able to do something like this - the trick is of course to use the actual referenced nodes, which is what we're grabbing with the id() function - it accepts a nodeset (all the @id attributes of the $matchedNodes).
<xsl:template match="/">
<xsl:variable name="matchedNodes" select="Exslt.Tags:getEverythingWithTags($tags)/root/node" />
<!--
Loops only a single node, just to get into the right context.
(See: https://gist.github.com/greystate/8576730)
-->
<xsl:for-each select="$currentPage">
<xsl:apply-templates select="id($matchedNodes/@id)">
<xsl:sort select="publishedDate" data-type="text" order="descending" />
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<!-- Output template -->
<xsl:template match="*[@isDoc]">
<p>
<xsl:value-of select="umbraco.library:FormatDateTime(publishedDate, 'dd MMMM yyyy')" />
</p>
</xsl:template>
Let me know if it works - maybe it needs some tuning, coming right out of my head without testing :-)
Will see if I can get it working with call-template. Just wanted to check if you knew if it's possible with the call-template approach or if it's only possible with apply-templates.
All working now. Used your idea to create a new variable that contained the ids in descending date order. Then tweaked my existing could to use the new variable and display the item.
<!-- Get all nodes that match the tag -->
<xsl:variable name="matchedNodes" select="Exslt.Tags:getEverythingWithTags($tags)/root/node" />
<!-- Sort matched nodes into date order-->
<xsl:variable name="sortedMacthedNodes">
<xsl:for-each select="$currentPage">
<xsl:apply-templates select="id($matchedNodes/@id)">
<xsl:sort select="publishedDate" data-type="text" order="descending" />
</xsl:apply-templates>
</xsl:for-each>
</xsl:variable>
<!-- Display each node -->
<xsl:for-each select="msxsl:node-set($sortedMacthedNodes)/node">
<xsl:if test="position() > $itemsPerPage * number($pageNumber - 1) and position() <= number($itemsPerPage * number($pageNumber - 1) + $itemsPerPage)">
<xsl:for-each select="umbraco.library:GetXmlNodeById(@id)">
<xsl:call-template name="article" />
</xsl:for-each>
</xsl:if>
</xsl:for-each>
Sort by date with getEverythingWithTags
Hi All,
Part of my xslt grabs all of the items with a certain tag.
I've tried to sort them using the normal sort method, but as matchedNodes is a list of ids there is no date to sort.
Does anyone have an example of sorting with 'getEverythingWithTags'?
Thanks,
Eddie
Hi Eddie,
You should be able to do something like this - the trick is of course to use the actual referenced nodes, which is what we're grabbing with the id() function - it accepts a nodeset (all the @id attributes of the $matchedNodes).
Let me know if it works - maybe it needs some tuning, coming right out of my head without testing :-)
/Chriztian
Hi Chriztian,
Thanks for the example. The existing xslt has a number of templates used for paging, output etc..
Below is the part of the code that grabs the tags.
Will see if I can get it working with call-template. Just wanted to check if you knew if it's possible with the call-template approach or if it's only possible with apply-templates.
Thanks, Eddie
Hi Chriztian,
All working now. Used your idea to create a new variable that contained the ids in descending date order. Then tweaked my existing could to use the new variable and display the item.
Thanks again for the pointers, Eddie
is working on a reply...