I have this xslt that are generating a course list. but
I can not get it to sort list against a field I have added on the document type
which I have called "sortOrder".The "sortOrder"field is of the type numeric. My code can be viewed below:
Hi Kim, you say you have added a field called sortOrder to your document type??? The sortOrder attribute (@sortOrder) is not the one you have created, but the one umbraco creates automatically based on the order of the nodes in the tree (right click on parent and choose sort to change it). I would suggest you use that method for sorting rather than add your own field to duplicate the functionality.
If you do want to keep your custom field (for whatever reason) ,change
Now it finds the sortOrder but not the right one ? it takes the sortOrder of the parentNode ?
how do I get it to take the sortOrder from the nodes with the document type "IIHKursus" right now it takes the sortOrder from the parent pages with has the document type "IIHEvent"
Note: I am all new to umbraco and xslt - and have taken over from someone else.. so I have another question how do I get to look at the xml file isn't that inside the database somewhere or ..
I can't get my xslt to sort
I have this xslt that are generating a course list. but I can not get it to sort list against a field I have added on the document type which I have called "sortOrder".The "sortOrder"field is of the type numeric. My code can be viewed below:
<?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"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<!-- Don't change this but create a 'number' element in your -->
<!-- macro with the alias of 'numberOfItems' -->
<xsl:variable name="numberOfItems" select="500"/>
<xsl:template match="/">
<!-- The fun starts here -->
<xsl:if test="$currentPage/@id = 1299">
Kurser
<ul style="padding:0px">
<xsl:for-each select="umbraco.library:GetXmlNodeById(1299)//node[@nodeTypeAlias='IIHKursus']">
<xsl:sort select="@sortOrder" order="descending"/>
<xsl:if test="position() <= $numberOfItems">
<li>
<xsl:value-of select="parent::node/@nodeName"/>
<br/>
<a href="{umbraco.library:NiceUrl(parent::node/@id)}">
<xsl:value-of select="@nodeName"/>
</a>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Try adding a data-type attribute to sort:
<xsl:sort select="@sortOrder" data-type="number" order="descending"/>
Otherwise try posting your XML as well.
Hi Kim, you say you have added a field called sortOrder to your document type??? The sortOrder attribute (@sortOrder) is not the one you have created, but the one umbraco creates automatically based on the order of the nodes in the tree (right click on parent and choose sort to change it). I would suggest you use that method for sorting rather than add your own field to duplicate the functionality.
If you do want to keep your custom field (for whatever reason) ,change
<xsl:sort select="@sortOrder" order="descending"/>
to
<xsl:sort select="data[@alias='sortOrder']" order="descending"/>
assuming you are using the old umbraco schema - it seems that way from your xslt.
Hope this helps
Thanks! I have added data-type="number" and also tried with
<xsl:sort select="data[@alias='sortOrder']" order="descending"/>
Now it finds the sortOrder but not the right one ? it takes the sortOrder of the parentNode ?
how do I get it to take the sortOrder from the nodes with the document type "IIHKursus" right now it takes the sortOrder from the parent pages with has the document type "IIHEvent"
Note: I am all new to umbraco and xslt - and have taken over from someone else.. so I have another question how do I get to look at the xml file isn't that inside the database somewhere or ..
Hi Kim
This is the package your looking for: XMLDump by @greystate aka Chriztian Steinmeier
is working on a reply...