Hi Everyone, im new to the forum, i like umbraco a lot, and im trying to use it in every single proyect that i have
Now, i have a big question about what is the best way to aproach sort functions using xslt
i have a front page where all the info for birthdays in my intranet is showed with name, month and day, but i just can find a way to sort the output of the macro in my frontpage.
<!-- update this variable on how deep your site map should be --> <xsl:variable name="maxLevelForSitemap" select="6"/> <xsl:template match="/"> <xsl:call-template name="drawNodes"> <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/> </xsl:call-template> </xsl:template> <xsl:template name="drawNodes"> <xsl:param name="parent"/> <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)"> <xsl:for-each select="$parent/*[@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]"> <!--<xsl:value-of select="name(./*[@isDoc])"/><br/>--> <xsl:sort select="birthdayEY" order="descending"/> <xsl:if test="@template = 1165"> <!-- Fix to all folders with template id --> <xsl:variable name="DateToday" select="umbraco.library:CurrentDate()"/> <xsl:if test="umbraco.library:FormatDateTime($DateToday, 'MMMM') = umbraco.library:FormatDateTime(birthdayEY, 'MMMM') ">
My guess is that you get it sorted, but per level or something like that. If you want a full list, I think you need to get all nodes at once in you first for each. Try something like this:
<xsl:templatename="drawNodes"> <xsl:paramname="parent"/> <xsl:iftest="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)"> <xsl:for-eachselect="$parent//*[@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]">
Notice that I have put a // after $parent, this should look through the whole hierarchy under $parent. Also, if you are only interested in a specific template Id, you might want to filter there too
If you do like this, your recursive call to drawnodes at the end can be removed also.
<!-- update this variable on how deep your site map should be --> <xsl:variablename="maxLevelForSitemap"select="6"/> <xsl:templatematch="/"> <xsl:call-templatename="drawNodes"> <xsl:with-paramname="parent"select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/> </xsl:call-template> </xsl:template> <xsl:templatename="drawNodes"> <xsl:paramname="parent"/> <xsl:variablename="DateToday"select="umbraco.library:CurrentDate()"/> <xsl:iftest="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)"> <xsl:for-eachselect="$parent//*[@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap and @template = 1165]"> <!--<xsl:value-of select="name(./*[@isDoc])"/><br/>--> <xsl:sortselect="birthdayEY"order="descending"/> <xsl:iftest="umbraco.library:FormatDateTime($DateToday, 'MMMM') = umbraco.library:FormatDateTime(birthdayEY, 'MMMM') ">
Hi Michael thanks for your comment, i follow your instructions, thanks for the tip, i accidentally open this twice and Daniel help me to find the solution, i let here the link just in case.
Cant Short using Sort Function
Hi Everyone, im new to the forum, i like umbraco a lot, and im trying to use it in every single proyect that i have
Now, i have a big question about what is the best way to aproach sort functions using xslt
i have a front page where all the info for birthdays in my intranet is showed with name, month and day, but i just can find a way to sort the output of the macro in my frontpage.
this is the code of the xlst.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="no"/>
<xsl:param name="currentPage"/>
<!-- update this variable on how deep your site map should be -->
<xsl:variable name="maxLevelForSitemap" select="6"/>
<xsl:template match="/">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
<xsl:for-each select="$parent/*[@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]">
<!--<xsl:value-of select="name(./*[@isDoc])"/><br/>-->
<xsl:sort select="birthdayEY" order="descending"/>
<xsl:if test="@template = 1165"> <!-- Fix to all folders with template id -->
<xsl:variable name="DateToday" select="umbraco.library:CurrentDate()"/>
<xsl:if test="umbraco.library:FormatDateTime($DateToday, 'MMMM') = umbraco.library:FormatDateTime(birthdayEY, 'MMMM') ">
<tr>
<td>
<span style="color:#747170"> <xsl:value-of select="nameEY"/></span>
</td>
<td>
<xsl:value-of select="umbraco.library:FormatDateTime(birthdayEY, 'MMMM d')"/>
</td>
</tr>
</xsl:if>
</xsl:if>
<xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]) > 0">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
and this is a picture of the output content in the front page
any ideas? thanks a lot for help i really need it!
Hi Andres,
My guess is that you get it sorted, but per level or something like that. If you want a full list, I think you need to get all nodes at once in you first for each. Try something like this:
Notice that I have put a // after $parent, this should look through the whole hierarchy under $parent. Also, if you are only interested in a specific template Id, you might want to filter there too
If you do like this, your recursive call to drawnodes at the end can be removed also.
Hope this helps!
Cheers,
Michael.
Maybe to make it more clear, this is the full XSL I would try:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="no"/>
<xsl:param name="currentPage"/>
<!-- update this variable on how deep your site map should be -->
<xsl:variable name="maxLevelForSitemap" select="6"/>
<xsl:template match="/">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:variable name="DateToday" select="umbraco.library:CurrentDate()"/>
<xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
<xsl:for-each select="$parent//*[@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap and @template = 1165]">
<!--<xsl:value-of select="name(./*[@isDoc])"/><br/>-->
<xsl:sort select="birthdayEY" order="descending"/>
<xsl:if test="umbraco.library:FormatDateTime($DateToday, 'MMMM') = umbraco.library:FormatDateTime(birthdayEY, 'MMMM') ">
<tr>
<td>
<span style="color:#747170"> <xsl:value-of select="nameEY"/></span>
</td>
<td>
<xsl:value-of select="umbraco.library:FormatDateTime(birthdayEY, 'MMMM d')"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Cheers,
Michael
Hi Michael thanks for your comment, i follow your instructions, thanks for the tip, i accidentally open this twice and Daniel help me to find the solution, i let here the link just in case.
http://our.umbraco.org/forum/developers/xslt/19292-Can't-Sort-Content-Using-Xslt
Thanks & Have a Good Day Michael!
You're very welcome :-)
Good to hear you sorted it out!
Have a nice week-end
Cheers,
Michael.
is working on a reply...