Search

I have a datasource that currently sorts via an input-field the following way:

  1. 1-1 0
  2. 1-1 1
  3. 1-1 2
  4. 1-10 10
  5. 1-10 11
  6. 1-10 12
  7. 1-9 0
  8. 1-9 1
  9. 1-9 2

How can I force the DS into sorting more sensible? Like this:

  1. 1-1 0
  2. 1-1 1
  3. 1-1 2
  4. 1-9 0
  5. 1-9 1
  6. 1-9 2
  7. 1-10 10
  8. 1-10 11
  9. 1-10 12

Is there any convert-to-number-function I can use in the DS-Editor?

A ~~reference field~~ might do the trick … will investigate. Any other insights are highly welcome! :)

Maybe you could use Reflection field to process a numeric value from this strings and than sort your entries based on this reflection.

Or maybe it would be meaningful to break these values into multiple fields, lets say also with reflection fields, if you need to keep this syntax (don't know the meaning of that value), and filter it in some way there.

Well, if the "reference field" you mention is not already the reflection field :) I don't know all of the fields ..

Thanks Juraj, indeed I meant to write Reflection field.

I ended up using the Reflection field with the following stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    extension-element-prefixes="dyn exslt"
  xmlns:exslt="http://exslt.org/common"
  xmlns:dyn="http://exslt.org/dynamic"
  xmlns:str="http://exslt.org/strings"
  >

<xsl:template match="data/entry">
    <data>
        <xsl:element name="sig-sort">
          <xsl:value-of select="format-number(sammlung/item/@id, '000000')"/>
            <xsl:text>-</xsl:text>
            <xsl:for-each select="str:tokenize(sig/@handle, '-_qwertzuiopasdfghjklyxcvbnm')">
               <xsl:value-of select="format-number(., '000000')"/>
               <xsl:if test="position()!=last()"><xsl:text>-</xsl:text></xsl:if>
            </xsl:for-each>
        </xsl:element>
    </data>
</xsl:template>

</xsl:stylesheet>

This turns an example entry like:

NL Mellin 1-1 07

into:

000005-000001-000001-000007

The first number sammlung/item/@id is used to group all items that belong to a certain collection. The rest is the retrieved numerical values in the string with plenty of leading zeroes for proper sort order. This will however omit any letters in the string for sorting.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details