Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kim 9 posts 30 karma points
    Dec 01, 2010 @ 15:21
    Kim
    0

    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 "&#x00A0;">
    ]>
    <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() &lt;= $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>

  • Sebastian Dammark 583 posts 1407 karma points
    Dec 01, 2010 @ 15:27
    Sebastian Dammark
    0

    Try adding a data-type attribute to sort:
    <xsl:sort select="@sortOrder" data-type="number" order="descending"/>

    Otherwise try posting your XML as well.

  • Josh Townson 67 posts 162 karma points
    Dec 02, 2010 @ 01:23
    Josh Townson
    0

    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

  • Kim 9 posts 30 karma points
    Dec 02, 2010 @ 08:54
    Kim
    0

    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"

  • Kim 9 posts 30 karma points
    Dec 02, 2010 @ 08:57
    Kim
    0

    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 ..

  • Sebastian Dammark 583 posts 1407 karma points
    Dec 02, 2010 @ 09:22
    Sebastian Dammark
    0

    Hi Kim

    This is the package your looking for: XMLDump by @greystate aka Chriztian Steinmeier

Please Sign in or register to post replies

Write your reply to:

Draft